Skip to content

Commit ed41d10

Browse files
committed
std: existing LinkedList is actually a TailQueue
1 parent b7811d3 commit ed41d10

File tree

8 files changed

+23
-18
lines changed

8 files changed

+23
-18
lines changed

src-self-hosted/compilation.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ pub const Compilation = struct {
160160
/// it uses an optional pointer so that tombstone removals are possible
161161
fn_link_set: event.Locked(FnLinkSet),
162162

163-
pub const FnLinkSet = std.LinkedList(?*Value.Fn);
163+
pub const FnLinkSet = std.TailQueue(?*Value.Fn);
164164

165165
windows_subsystem_windows: bool,
166166
windows_subsystem_console: bool,

src-self-hosted/value.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ pub const Value = struct {
186186
/// Path to the object file that contains this function
187187
containing_object: Buffer,
188188

189-
link_set_node: *std.LinkedList(?*Value.Fn).Node,
189+
link_set_node: *std.TailQueue(?*Value.Fn).Node,
190190

191191
/// Creates a Fn value with 1 ref
192192
/// Takes ownership of symbol_name

std/atomic/queue.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub fn Queue(comptime T: type) type {
1414
mutex: std.Mutex,
1515

1616
pub const Self = @This();
17-
pub const Node = std.LinkedList(T).Node;
17+
pub const Node = std.TailQueue(T).Node;
1818

1919
pub fn init() Self {
2020
return Self{

std/child_process.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const BufMap = std.BufMap;
1313
const Buffer = std.Buffer;
1414
const builtin = @import("builtin");
1515
const Os = builtin.Os;
16-
const LinkedList = std.LinkedList;
16+
const TailQueue = std.TailQueue;
1717
const maxInt = std.math.maxInt;
1818

1919
pub const ChildProcess = struct {
@@ -48,7 +48,7 @@ pub const ChildProcess = struct {
4848
pub cwd: ?[]const u8,
4949

5050
err_pipe: if (os.windows.is_the_target) void else [2]os.fd_t,
51-
llnode: if (os.windows.is_the_target) void else LinkedList(*ChildProcess).Node,
51+
llnode: if (os.windows.is_the_target) void else TailQueue(*ChildProcess).Node,
5252

5353
pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError ||
5454
os.ChangeCurDirError || windows.CreateProcessError;
@@ -388,7 +388,7 @@ pub const ChildProcess = struct {
388388

389389
self.pid = pid;
390390
self.err_pipe = err_pipe;
391-
self.llnode = LinkedList(*ChildProcess).Node.init(self);
391+
self.llnode = TailQueue(*ChildProcess).Node.init(self);
392392
self.term = null;
393393

394394
if (self.stdin_behavior == StdIo.Pipe) {

std/event/net.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub const Server = struct {
1919
waiting_for_emfile_node: PromiseNode,
2020
listen_resume_node: event.Loop.ResumeNode,
2121

22-
const PromiseNode = std.LinkedList(promise).Node;
22+
const PromiseNode = std.TailQueue(promise).Node;
2323

2424
pub fn init(loop: *Loop) Server {
2525
// TODO can't initialize handler coroutine here because we need well defined copy elision

std/heap.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ pub const ArenaAllocator = struct {
347347
pub allocator: Allocator,
348348

349349
child_allocator: *Allocator,
350-
buffer_list: std.LinkedList([]u8),
350+
buffer_list: std.TailQueue([]u8),
351351
end_index: usize,
352352

353-
const BufNode = std.LinkedList([]u8).Node;
353+
const BufNode = std.TailQueue([]u8).Node;
354354

355355
pub fn init(child_allocator: *Allocator) ArenaAllocator {
356356
return ArenaAllocator{
@@ -359,7 +359,7 @@ pub const ArenaAllocator = struct {
359359
.shrinkFn = shrink,
360360
},
361361
.child_allocator = child_allocator,
362-
.buffer_list = std.LinkedList([]u8).init(),
362+
.buffer_list = std.TailQueue([]u8).init(),
363363
.end_index = 0,
364364
};
365365
}

std/linked_list.zig

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@ const testing = std.testing;
55
const mem = std.mem;
66
const Allocator = mem.Allocator;
77

8-
/// Generic doubly linked list.
9-
pub fn LinkedList(comptime T: type) type {
8+
/// A tail queue is headed by a pair of pointers, one to the head of the
9+
/// list and the other to the tail of the list. The elements are doubly
10+
/// linked so that an arbitrary element can be removed without a need to
11+
/// traverse the list. New elements can be added to the list before or
12+
/// after an existing element, at the head of the list, or at the end of
13+
/// the list. A tail queue may be traversed in either direction.
14+
pub fn TailQueue(comptime T: type) type {
1015
return struct {
1116
const Self = @This();
1217

@@ -219,9 +224,9 @@ pub fn LinkedList(comptime T: type) type {
219224
};
220225
}
221226

222-
test "basic linked list test" {
227+
test "basic TailQueue test" {
223228
const allocator = debug.global_allocator;
224-
var list = LinkedList(u32).init();
229+
var list = TailQueue(u32).init();
225230

226231
var one = try list.createNode(1, allocator);
227232
var two = try list.createNode(2, allocator);
@@ -271,10 +276,10 @@ test "basic linked list test" {
271276
testing.expect(list.len == 2);
272277
}
273278

274-
test "linked list concatenation" {
279+
test "TailQueue concatenation" {
275280
const allocator = debug.global_allocator;
276-
var list1 = LinkedList(u32).init();
277-
var list2 = LinkedList(u32).init();
281+
var list1 = TailQueue(u32).init();
282+
var list2 = TailQueue(u32).init();
278283

279284
var one = try list1.createNode(1, allocator);
280285
defer list1.destroyNode(one, allocator);

std/std.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub const Buffer = @import("buffer.zig").Buffer;
77
pub const BufferOutStream = @import("io.zig").BufferOutStream;
88
pub const DynLib = @import("dynamic_library.zig").DynLib;
99
pub const HashMap = @import("hash_map.zig").HashMap;
10-
pub const LinkedList = @import("linked_list.zig").LinkedList;
1110
pub const Mutex = @import("mutex.zig").Mutex;
1211
pub const PackedIntArrayEndian = @import("packed_int_array.zig").PackedIntArrayEndian;
1312
pub const PackedIntArray = @import("packed_int_array.zig").PackedIntArray;
@@ -18,6 +17,7 @@ pub const StaticallyInitializedMutex = @import("statically_initialized_mutex.zig
1817
pub const SegmentedList = @import("segmented_list.zig").SegmentedList;
1918
pub const SpinLock = @import("spinlock.zig").SpinLock;
2019
pub const ChildProcess = @import("child_process.zig").ChildProcess;
20+
pub const TailQueue = @import("linked_list.zig").TailQueue;
2121
pub const Thread = @import("thread.zig").Thread;
2222

2323
pub const atomic = @import("atomic.zig");

0 commit comments

Comments
 (0)