aboutsummaryrefslogtreecommitdiff
path: root/src/gss.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-04-26 16:55:08 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-04-26 16:55:08 +0200
commit922db9c5fc50b82182fb5a0b4e3c8bb18fc2e0ab (patch)
tree0bb2f9098811d2af6ba44bcde17a1f77d4bd12a4 /src/gss.zig
parentcf4d53c3eb35028839e6b267230c23df68b1e94a (diff)
use gss
Diffstat (limited to 'src/gss.zig')
-rw-r--r--src/gss.zig23
1 files changed, 21 insertions, 2 deletions
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 });
+ }
};
}