Zig utility library
1
fork

Configure Feed

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

minor changes

IamPyu 3e2b9f8d 2bba5686

+33 -8
-1
build.zig
··· 9 9 .target = target, 10 10 .optimize = optimize, 11 11 }); 12 - mod.addImport("mitochondria", mod); 13 12 14 13 const lib = b.addLibrary(.{ 15 14 .name = "mitochondria",
+1
flake.nix
··· 41 41 buildInputs = with pkgs; [ 42 42 zig 43 43 zls 44 + lldb 44 45 ]; 45 46 }; 46 47 };
+1 -1
src/SparseSet.zig
··· 134 134 _ = list.remove(i); 135 135 _ = try list.insert("it's a beautiful day"); 136 136 137 - const SliceIterator = @import("mitochondria").SliceIterator; 137 + const SliceIterator = @import("./slice_iterator.zig").SliceIterator; 138 138 139 139 var iter = SliceIterator([]const u8).init(list.asSlice()); 140 140
+4 -3
src/StringBuilder.zig
··· 36 36 /// Reserve additional space for the string builder or reduce its size. 37 37 pub fn resize(self: *Self, size: usize) !void { 38 38 if (size < self.capacity) { 39 + self.buf = try self.allocator.realloc(self.buf, size); 39 40 self.capacity = size; 40 - self.buf = try self.allocator.realloc(self.buf, self.capacity); 41 41 return; 42 42 } 43 43 44 - self.capacity = size * 2; 45 - self.buf = try self.allocator.realloc(self.buf, self.capacity); 44 + const newcap = size * 2; 45 + self.buf = try self.allocator.realloc(self.buf, newcap); 46 + self.capacity = newcap; 46 47 } 47 48 48 49 /// Append a slice to the string builder
+27 -3
src/binary_tree.zig
··· 17 17 pub fn init(x: T) Node { 18 18 return Node{ .data = x }; 19 19 } 20 + 21 + pub fn initAlloc(allocator: Allocator, x: T) !*Node { 22 + var node = try allocator.create(Node); 23 + node.data = x; 24 + return node; 25 + } 20 26 }; 21 27 22 28 pub const Iter = struct { ··· 58 64 if (ptr.*) |p| { 59 65 // TODO: fix segfault when checking for null pointer 60 66 // TODO: i found the same issue in our queue 61 - if (p.left) |_| { 67 + 68 + const b = p.*.left != null; 69 + if (b) { 62 70 p.right = self.insertAt(&p.right, node); 63 71 } else { 64 72 p.left = self.insertAt(&p.left, node); 65 73 } 66 74 67 - return ptr.*.?; 75 + return p; 68 76 } else { 69 77 ptr.* = node; 70 - return ptr.*.?; 78 + return node; 71 79 } 72 80 } 73 81 ··· 133 141 } 134 142 std.debug.print("\n", .{}); 135 143 } 144 + 145 + test "binary_tree2" { 146 + std.debug.print("binary_tree2\n", .{}); 147 + const T = BinaryTree(u32); 148 + var arena = std.heap.ArenaAllocator.init(std.testing.allocator); 149 + defer arena.deinit(); 150 + 151 + var bt = T.init(); 152 + bt.root = try T.Node.initAlloc(arena.allocator(), 0); 153 + 154 + for (0..5) |i| { 155 + const node = try T.Node.initAlloc(arena.allocator(), @intCast(i + 1)); 156 + 157 + _ = bt.insert(node); 158 + } 159 + }