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 {...@@ -160,7 +160,7 @@ pub const Compilation = struct {
160 /// it uses an optional pointer so that tombstone removals are possible160 /// it uses an optional pointer so that tombstone removals are possible
161 fn_link_set: event.Locked(FnLinkSet),161 fn_link_set: event.Locked(FnLinkSet),
162162
163 pub const FnLinkSet = std.LinkedList(?*Value.Fn);163 pub const FnLinkSet = std.TailQueue(?*Value.Fn);
164164
165 windows_subsystem_windows: bool,165 windows_subsystem_windows: bool,
166 windows_subsystem_console: bool,166 windows_subsystem_console: bool,
src-self-hosted/value.zig+1-1
...@@ -186,7 +186,7 @@ pub const Value = struct {...@@ -186,7 +186,7 @@ pub const Value = struct {
186 /// Path to the object file that contains this function186 /// Path to the object file that contains this function
187 containing_object: Buffer,187 containing_object: Buffer,
188188
189 link_set_node: *std.LinkedList(?*Value.Fn).Node,189 link_set_node: *std.TailQueue(?*Value.Fn).Node,
190190
191 /// Creates a Fn value with 1 ref191 /// Creates a Fn value with 1 ref
192 /// Takes ownership of symbol_name192 /// Takes ownership of symbol_name
std/atomic/queue.zig+1-1
...@@ -14,7 +14,7 @@ pub fn Queue(comptime T: type) type {...@@ -14,7 +14,7 @@ pub fn Queue(comptime T: type) type {
14 mutex: std.Mutex,14 mutex: std.Mutex,
1515
16 pub const Self = @This();16 pub const Self = @This();
17 pub const Node = std.LinkedList(T).Node;17 pub const Node = std.TailQueue(T).Node;
1818
19 pub fn init() Self {19 pub fn init() Self {
20 return Self{20 return Self{
std/child_process.zig+3-3
...@@ -13,7 +13,7 @@ const BufMap = std.BufMap;...@@ -13,7 +13,7 @@ const BufMap = std.BufMap;
13const Buffer = std.Buffer;13const Buffer = std.Buffer;
14const builtin = @import("builtin");14const builtin = @import("builtin");
15const Os = builtin.Os;15const Os = builtin.Os;
16const LinkedList = std.LinkedList;16const TailQueue = std.TailQueue;
17const maxInt = std.math.maxInt;17const maxInt = std.math.maxInt;
1818
19pub const ChildProcess = struct {19pub const ChildProcess = struct {
...@@ -48,7 +48,7 @@ pub const ChildProcess = struct {...@@ -48,7 +48,7 @@ pub const ChildProcess = struct {
48 pub cwd: ?[]const u8,48 pub cwd: ?[]const u8,
4949
50 err_pipe: if (os.windows.is_the_target) void else [2]os.fd_t,50 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
53 pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError ||53 pub const SpawnError = error{OutOfMemory} || os.ExecveError || os.SetIdError ||
54 os.ChangeCurDirError || windows.CreateProcessError;54 os.ChangeCurDirError || windows.CreateProcessError;
...@@ -388,7 +388,7 @@ pub const ChildProcess = struct {...@@ -388,7 +388,7 @@ pub const ChildProcess = struct {
388388
389 self.pid = pid;389 self.pid = pid;
390 self.err_pipe = err_pipe;390 self.err_pipe = err_pipe;
391 self.llnode = LinkedList(*ChildProcess).Node.init(self);391 self.llnode = TailQueue(*ChildProcess).Node.init(self);
392 self.term = null;392 self.term = null;
393393
394 if (self.stdin_behavior == StdIo.Pipe) {394 if (self.stdin_behavior == StdIo.Pipe) {
std/event/net.zig+1-1
...@@ -19,7 +19,7 @@ pub const Server = struct {...@@ -19,7 +19,7 @@ pub const Server = struct {
19 waiting_for_emfile_node: PromiseNode,19 waiting_for_emfile_node: PromiseNode,
20 listen_resume_node: event.Loop.ResumeNode,20 listen_resume_node: event.Loop.ResumeNode,
2121
22 const PromiseNode = std.LinkedList(promise).Node;22 const PromiseNode = std.TailQueue(promise).Node;
2323
24 pub fn init(loop: *Loop) Server {24 pub fn init(loop: *Loop) Server {
25 // TODO can't initialize handler coroutine here because we need well defined copy elision25 // 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 {...@@ -347,10 +347,10 @@ pub const ArenaAllocator = struct {
347 pub allocator: Allocator,347 pub allocator: Allocator,
348348
349 child_allocator: *Allocator,349 child_allocator: *Allocator,
350 buffer_list: std.LinkedList([]u8),350 buffer_list: std.TailQueue([]u8),
351 end_index: usize,351 end_index: usize,
352352
353 const BufNode = std.LinkedList([]u8).Node;353 const BufNode = std.TailQueue([]u8).Node;
354354
355 pub fn init(child_allocator: *Allocator) ArenaAllocator {355 pub fn init(child_allocator: *Allocator) ArenaAllocator {
356 return ArenaAllocator{356 return ArenaAllocator{
...@@ -359,7 +359,7 @@ pub const ArenaAllocator = struct {...@@ -359,7 +359,7 @@ pub const ArenaAllocator = struct {
359 .shrinkFn = shrink,359 .shrinkFn = shrink,
360 },360 },
361 .child_allocator = child_allocator,361 .child_allocator = child_allocator,
362 .buffer_list = std.LinkedList([]u8).init(),362 .buffer_list = std.TailQueue([]u8).init(),
363 .end_index = 0,363 .end_index = 0,
364 };364 };
365 }365 }
std/linked_list.zig+12-7
...@@ -5,8 +5,13 @@ const testing = std.testing;...@@ -5,8 +5,13 @@ const testing = std.testing;
5const mem = std.mem;5const mem = std.mem;
6const Allocator = mem.Allocator;6const Allocator = mem.Allocator;
77
8/// Generic doubly linked list.8/// A tail queue is headed by a pair of pointers, one to the head of the
9pub fn LinkedList(comptime T: type) type {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 {
10 return struct {15 return struct {
11 const Self = @This();16 const Self = @This();
1217
...@@ -219,9 +224,9 @@ pub fn LinkedList(comptime T: type) type {...@@ -219,9 +224,9 @@ pub fn LinkedList(comptime T: type) type {
219 };224 };
220}225}
221226
222test "basic linked list test" {227test "basic TailQueue test" {
223 const allocator = debug.global_allocator;228 const allocator = debug.global_allocator;
224 var list = LinkedList(u32).init();229 var list = TailQueue(u32).init();
225230
226 var one = try list.createNode(1, allocator);231 var one = try list.createNode(1, allocator);
227 var two = try list.createNode(2, allocator);232 var two = try list.createNode(2, allocator);
...@@ -271,10 +276,10 @@ test "basic linked list test" {...@@ -271,10 +276,10 @@ test "basic linked list test" {
271 testing.expect(list.len == 2);276 testing.expect(list.len == 2);
272}277}
273278
274test "linked list concatenation" {279test "TailQueue concatenation" {
275 const allocator = debug.global_allocator;280 const allocator = debug.global_allocator;
276 var list1 = LinkedList(u32).init();281 var list1 = TailQueue(u32).init();
277 var list2 = LinkedList(u32).init();282 var list2 = TailQueue(u32).init();
278283
279 var one = try list1.createNode(1, allocator);284 var one = try list1.createNode(1, allocator);
280 defer list1.destroyNode(one, allocator);285 defer list1.destroyNode(one, allocator);
std/std.zig+1-1
...@@ -7,7 +7,6 @@ pub const Buffer = @import("buffer.zig").Buffer;...@@ -7,7 +7,6 @@ pub const Buffer = @import("buffer.zig").Buffer;
7pub const BufferOutStream = @import("io.zig").BufferOutStream;7pub const BufferOutStream = @import("io.zig").BufferOutStream;
8pub const DynLib = @import("dynamic_library.zig").DynLib;8pub const DynLib = @import("dynamic_library.zig").DynLib;
9pub const HashMap = @import("hash_map.zig").HashMap;9pub const HashMap = @import("hash_map.zig").HashMap;
10pub const LinkedList = @import("linked_list.zig").LinkedList;
11pub const Mutex = @import("mutex.zig").Mutex;10pub const Mutex = @import("mutex.zig").Mutex;
12pub const PackedIntArrayEndian = @import("packed_int_array.zig").PackedIntArrayEndian;11pub const PackedIntArrayEndian = @import("packed_int_array.zig").PackedIntArrayEndian;
13pub const PackedIntArray = @import("packed_int_array.zig").PackedIntArray;12pub const PackedIntArray = @import("packed_int_array.zig").PackedIntArray;
...@@ -18,6 +17,7 @@ pub const StaticallyInitializedMutex = @import("statically_initialized_mutex.zig...@@ -18,6 +17,7 @@ pub const StaticallyInitializedMutex = @import("statically_initialized_mutex.zig
18pub const SegmentedList = @import("segmented_list.zig").SegmentedList;17pub const SegmentedList = @import("segmented_list.zig").SegmentedList;
19pub const SpinLock = @import("spinlock.zig").SpinLock;18pub const SpinLock = @import("spinlock.zig").SpinLock;
20pub const ChildProcess = @import("child_process.zig").ChildProcess;19pub const ChildProcess = @import("child_process.zig").ChildProcess;
20pub const TailQueue = @import("linked_list.zig").TailQueue;
21pub const Thread = @import("thread.zig").Thread;21pub const Thread = @import("thread.zig").Thread;
2222
23pub const atomic = @import("atomic.zig");23pub const atomic = @import("atomic.zig");