authorgravatar for saurabh.m@proton.meSaurabh Mishra <saurabh.m@proton.me> 2026-06-11 05:43:57+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-06-11 05:43:57+02:00
log3a8097ffd4a6370e8188767c6fff409e02186f72
tree9cff4e8939883c0243174ce489153d49df279bb6
parent57ca3512e429f962edc15ea2b24a57f9c778320d

`std.DoublyLinkedList`: rename `pop` to `popLast` (#35692)

Rename `pop` to `popLast` as there's a `popFirst` method in `std.DoublyLinkedList`. This naming is similar to the front and back methods in `std.Deque`, which is also a double-ended container. Reviewed-on: https://codeberg.org/ziglang/zig/pulls/35692 Reviewed-by: Andrew Kelley <andrew@ziglang.org>

1 files changed, 10 insertions(+), 10 deletions(-)

lib/std/DoublyLinkedList.zig+10-10
......@@ -127,20 +127,17 @@ pub fn remove(list: *DoublyLinkedList, node: *Node) void {
127127 }
128128}
129129
130/// Remove and return the last node in the list.
131///
132/// Returns:
133/// A pointer to the last node in the list.
134pub fn pop(list: *DoublyLinkedList) ?*Node {
130/// Remove and return a pointer to the last node in the list.
131pub fn popLast(list: *DoublyLinkedList) ?*Node {
135132 const last = list.last orelse return null;
136133 list.remove(last);
137134 return last;
138135}
139136
140/// Remove and return the first node in the list.
141///
142/// Returns:
143/// A pointer to the first node in the list.
137/// Deprecated in favor of `popLast`
138pub const pop = popLast;
139
140/// Remove and return a pointer to the first node in the list.
144141pub fn popFirst(list: *DoublyLinkedList) ?*Node {
145142 const first = list.first orelse return null;
146143 list.remove(first);
......@@ -200,11 +197,14 @@ test "basics" {
200197 }
201198
202199 _ = list.popFirst(); // {2, 3, 4, 5}
203 _ = list.pop(); // {2, 3, 4}
200 _ = list.popLast(); // {2, 3, 4}
204201 list.remove(&three.node); // {2, 4}
205202
203 // peek first and last elements of the list
206204 try testing.expect(@as(*L, @fieldParentPtr("node", list.first.?)).data == 2);
207205 try testing.expect(@as(*L, @fieldParentPtr("node", list.last.?)).data == 4);
206
207 // list length
208208 try testing.expect(list.len() == 2);
209209}
210210