From 3a8097ffd4a6370e8188767c6fff409e02186f72 Mon Sep 17 00:00:00 2001 From: Saurabh Mishra Date: Thu, 11 Jun 2026 05:43:57 +0200 Subject: [PATCH] `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 --- lib/std/DoublyLinkedList.zig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/std/DoublyLinkedList.zig b/lib/std/DoublyLinkedList.zig index b7a5ed2e112cb926396261047becfebcc934f553..a792dc9b4ec291fc9be8a1841e180305cd45fa3d 100644 --- 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); } -- 2.54.0