From 922db9c5fc50b82182fb5a0b4e3c8bb18fc2e0ab Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 26 Apr 2025 16:55:08 +0200 Subject: use gss --- src/gss.zig | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/gss.zig') diff --git a/src/gss.zig b/src/gss.zig index ba8542d..8f81d80 100644 --- a/src/gss.zig +++ b/src/gss.zig @@ -4,7 +4,7 @@ pub fn Node(T: type) type { return struct { const Self = @This(); - parent: ?*Node = null, + parent: ?*Self = null, state: T, pub fn init(state: T) Self { @@ -18,7 +18,14 @@ pub fn Node(T: type) type { return node; } - pub fn pop(self: *Self, allocator: std.mem.Allocator) struct { T, *Self } { + pub fn clone(self: *Self, state: T, allocator: std.mem.Allocator) !*Self { + const node = try allocator.create(Self); + node.parent = self.parent; + node.state = state; + return node; + } + + pub fn pop(self: *Self, allocator: std.mem.Allocator) struct { T, ?*Self } { const parent = self.parent; const state = self.state; @@ -26,5 +33,17 @@ pub fn Node(T: type) type { return .{ state, parent }; } + + pub fn format( + self: *const Self, + comptime fmt: []const u8, + options: std.fmt.FormatOptions, + writer: anytype, + ) !void { + _ = fmt; + _ = options; + + try writer.print("Node {{ {} }}", .{ self.state }); + } }; } -- cgit v1.2.3-70-g09d2