Zig utility library
1
fork

Configure Feed

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

Improve documentation

IamPyu 3a0adb49 20c04009

+26 -9
-7
src/BinaryTree.zig
··· 120 120 }; 121 121 } 122 122 123 - fn traverse(node: anytype) void { 124 - if (node == null) return; 125 - std.debug.print("{d} ", .{node.?.data}); 126 - traverse(node.?.left); 127 - traverse(node.?.right); 128 - } 129 - 130 123 test "binary_tree" { 131 124 const T = ArrayBinaryTree(u32); 132 125 var abt = try T.init(std.testing.allocator);
+2
src/Queue.zig
··· 12 12 next: ?*Node = null, 13 13 prev: ?*Node = null, 14 14 15 + /// Create a node 15 16 pub fn init(value: T) Node { 16 17 return Node{ .value = value }; 17 18 } 18 19 20 + /// Allocate a node 19 21 pub fn initAlloc(gpa: Allocator, value: T) !*Node { 20 22 const ptr = try gpa.create(Node); 21 23 ptr.* = Node.init(value);
+3
src/RingBuffer.zig
··· 1 + //! Ring buffer 1 2 const std = @import("std"); 2 3 4 + /// Ring buffer 3 5 pub fn RingBuffer(T: type, comptime capacity: usize) type { 4 6 return struct { 5 7 const Self = @This(); ··· 12 14 write_index: usize = 0, 13 15 read_index: usize = 0, 14 16 17 + /// Create a ring buffer 15 18 pub fn init() Self { 16 19 return Self{}; 17 20 }
+2 -1
src/SliceIterator.zig
··· 1 1 const std = @import("std"); 2 2 3 + /// A generic iterator for slices 3 4 pub fn SliceIterator(comptime T: type) type { 4 5 return struct { 5 6 const Self = @This(); ··· 7 8 slice: []const T, 8 9 index: usize = 0, 9 10 10 - /// Create the SliceIterator from a slice 11 + /// Create the slice iterator from a slice 11 12 pub fn init(slice: []const T) Self { 12 13 return Self{ .slice = slice }; 13 14 }
+2
src/SparseSet.zig
··· 1 + //! Sparse Set 1 2 const std = @import("std"); 2 3 const Allocator = std.mem.Allocator; 3 4 const ArrayList = std.ArrayList; 4 5 6 + /// Sparse Set 5 7 pub fn SparseSet(comptime T: type) type { 6 8 return struct { 7 9 const Self = @This();
+3
src/StringBuilder.zig
··· 1 + //! A simple way to build strings 2 + 1 3 const std = @import("std"); 2 4 const Allocator = std.mem.Allocator; 3 5 4 6 const Self = @This(); 5 7 8 + /// An error that can occur when using a `StringBuilder` 6 9 pub const Error = Allocator.Error; 7 10 8 11 allocator: Allocator,
+6
src/math.zig
··· 1 + //! Math utilities 2 + 1 3 const std = @import("std"); 2 4 const math = std.math; 3 5 6 + /// The type of an angle 4 7 pub const AngleType = enum { 5 8 Rad, 6 9 Deg, 7 10 }; 8 11 12 + /// An angle, either radians or degrees 9 13 pub fn Angle(comptime T: type) type { 10 14 return union(AngleType) { 11 15 const Self = @This(); ··· 41 45 }; 42 46 } 43 47 48 + /// Create an angle of degrees 44 49 pub fn angleDeg(v: anytype) Angle(@TypeOf(v)) { 45 50 return Angle(@TypeOf(v)).initDegrees(v); 46 51 } 47 52 53 + /// Create an angle of radians 48 54 pub fn angleRad(v: anytype) Angle(@TypeOf(v)) { 49 55 return Angle(@TypeOf(v)).initRadians(v); 50 56 }
+4
src/mem.zig
··· 1 + //! Memory utilities 2 + 1 3 const std = @import("std"); 2 4 const mem = std.mem; 3 5 6 + /// Split a slice once 4 7 pub fn splitOnce(comptime T: type, haystack: []const T, needle: []const T) ?struct { []const T, []const T } { 5 8 if (mem.indexOf(T, haystack, needle)) |index| { 6 9 const lth = haystack[0..index]; ··· 11 14 return null; 12 15 } 13 16 17 + /// Split a slice once using a scalar value 14 18 pub fn splitOnceScalar(comptime T: type, slice: []const T, delimeter: T) ?struct { []const T, []const T } { 15 19 return splitOnce(T, slice, &[_]T{delimeter}); 16 20 }
+4 -1
src/packet.zig
··· 1 + //! Generic network packets 2 + 1 3 const std = @import("std"); 2 4 const Io = std.Io; 3 5 const net = std.net; ··· 7 9 8 10 // TODO: compression 9 11 12 + /// Type used to determine packet sizes 10 13 pub const PacketSize = u64; 11 14 15 + /// Endian used for packet headers 12 16 pub const HEADER_ENDIAN = std.builtin.Endian.big; 13 17 14 18 pub fn Packet(T: type) type { ··· 45 49 /// Deserialize a serialized payload 46 50 pub fn deserialize(s: []const u8, allocator: Allocator) !T { 47 51 return try zon.parse.fromSlice(T, allocator, s, null, .{}); 48 - // return try json.parseFromSlice(T, allocator, s, .{}); 49 52 } 50 53 51 54 /// Send the packet to a writer