authorgravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-05-04 13:54:28+10:00
committergravatar for quae@daurnimator.comdaurnimator <quae@daurnimator.com> 2019-06-10 15:41:40+10:00
loged41d10a068065ea80f93736926d9c3240d62c49
tree696f68dbd2e45a48f86680394ed21b85c879578a
parentb7811d32690a9f3b4912635e16e6aa5ace25362c
signature Commit is signed but in an unrecognized format.

std: existing LinkedList is actually a TailQueue


8 files changed, 23 insertions(+), 18 deletions(-)

src-self-hosted/compilation.zig+1-1
......@@ -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+1-1
......@@ -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+1-1
......@@ -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+3-3
......@@ -13,7 +13,7 @@ const BufMap = std.BufMap;
1313const Buffer = std.Buffer;
1414const builtin = @import("builtin");
1515const Os = builtin.Os;
16const LinkedList = std.LinkedList;
16const TailQueue = std.TailQueue;
1717const maxInt = std.math.maxInt;
1818
1919pub 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+1-1
......@@ -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+3-3
......@@ -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+12-7
......@@ -5,8 +5,13 @@ const testing = std.testing;
55const mem = std.mem;
66const Allocator = mem.Allocator;
77
8/// Generic doubly linked list.
9pub 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.
14pub 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
222test "basic linked list test" {
227test "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
274test "linked list concatenation" {
279test "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+1-1
......@@ -7,7 +7,6 @@ pub const Buffer = @import("buffer.zig").Buffer;
77pub const BufferOutStream = @import("io.zig").BufferOutStream;
88pub const DynLib = @import("dynamic_library.zig").DynLib;
99pub const HashMap = @import("hash_map.zig").HashMap;
10pub const LinkedList = @import("linked_list.zig").LinkedList;
1110pub const Mutex = @import("mutex.zig").Mutex;
1211pub const PackedIntArrayEndian = @import("packed_int_array.zig").PackedIntArrayEndian;
1312pub const PackedIntArray = @import("packed_int_array.zig").PackedIntArray;
......@@ -18,6 +17,7 @@ pub const StaticallyInitializedMutex = @import("statically_initialized_mutex.zig
1817pub const SegmentedList = @import("segmented_list.zig").SegmentedList;
1918pub const SpinLock = @import("spinlock.zig").SpinLock;
2019pub const ChildProcess = @import("child_process.zig").ChildProcess;
20pub const TailQueue = @import("linked_list.zig").TailQueue;
2121pub const Thread = @import("thread.zig").Thread;
2222
2323pub const atomic = @import("atomic.zig");