zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 3a8097ffd4a6370e8188767c6fff409e02186f72 (tree)
parent 57ca3512e429f962edc15ea2b24a57f9c778320d
Author: Saurabh Mishra <saurabh.m@proton.me>
Date:   Thu, 11 Jun 2026 05:43:57 +0200

`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>

Diffstat:
Mlib/std/DoublyLinkedList.zig | 20++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/lib/std/DoublyLinkedList.zig b/lib/std/DoublyLinkedList.zig @@ -127,20 +127,17 @@ pub fn remove(list: *DoublyLinkedList, node: *Node) void { } } -/// Remove and return the last node in the list. -/// -/// Returns: -/// A pointer to the last node in the list. -pub fn pop(list: *DoublyLinkedList) ?*Node { +/// Remove and return a pointer to the last node in the list. +pub fn popLast(list: *DoublyLinkedList) ?*Node { const last = list.last orelse return null; list.remove(last); return last; } -/// Remove and return the first node in the list. -/// -/// Returns: -/// A pointer to the first node in the list. +/// Deprecated in favor of `popLast` +pub const pop = popLast; + +/// Remove and return a pointer to the first node in the list. pub fn popFirst(list: *DoublyLinkedList) ?*Node { const first = list.first orelse return null; list.remove(first); @@ -200,11 +197,14 @@ test "basics" { } _ = list.popFirst(); // {2, 3, 4, 5} - _ = list.pop(); // {2, 3, 4} + _ = list.popLast(); // {2, 3, 4} list.remove(&three.node); // {2, 4} + // peek first and last elements of the list try testing.expect(@as(*L, @fieldParentPtr("node", list.first.?)).data == 2); try testing.expect(@as(*L, @fieldParentPtr("node", list.last.?)).data == 4); + + // list length try testing.expect(list.len() == 2); }