Zig utility library
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add `initCapacity` to Queue

IamPyu 4a550bb3 946e037f

+12 -3
+12 -3
src/data/Queue.zig
··· 108 108 pub fn init(allocator: Allocator) !Self { 109 109 return .{ 110 110 .allocator = allocator, 111 - .nodes = try NodeList.initCapacity(allocator, 10), 111 + .nodes = .empty, 112 + .queue = IQueue.init(), 113 + }; 114 + } 115 + 116 + pub fn initCapacity(allocator: Allocator, cap: usize) !Self { 117 + return .{ 118 + .allocator = allocator, 119 + .nodes = try NodeList.initCapacity(allocator, cap), 112 120 .queue = IQueue.init(), 113 121 }; 114 122 } ··· 136 144 } 137 145 138 146 test "queue" { 139 - var queue = try ArrayQueue(i32).init(std.testing.allocator); 147 + const cap = 5000; 148 + var queue = try ArrayQueue(i32).initCapacity(std.testing.allocator, cap); 140 149 defer queue.deinit(); 141 150 142 151 try queue.enqueue(1); ··· 144 153 _ = queue.dequeue(); 145 154 try queue.enqueue(3); 146 155 147 - for (0..50) |i| { 156 + for (0..cap) |i| { 148 157 try queue.enqueue(@intCast(i)); 149 158 } 150 159