diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-04-26 14:23:28 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-04-26 14:23:28 +0200 |
| commit | cf4d53c3eb35028839e6b267230c23df68b1e94a (patch) | |
| tree | ac564add1e8b0ee1b9d111a7692ec2ab7fc0499e /src/gss.zig | |
| parent | f593da7580f423b1405f4705081368acef0b3c21 (diff) | |
first working implementation (unoptimized)
Diffstat (limited to 'src/gss.zig')
| -rw-r--r-- | src/gss.zig | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/gss.zig b/src/gss.zig new file mode 100644 index 0000000..ba8542d --- /dev/null +++ b/src/gss.zig @@ -0,0 +1,30 @@ +const std = @import("std"); + +pub fn Node(T: type) type { + return struct { + const Self = @This(); + + parent: ?*Node = null, + state: T, + + pub fn init(state: T) Self { + return Self { .state = state }; + } + + pub fn push(self: *Self, state: T, allocator: std.mem.Allocator) !*Self { + const node = try allocator.create(Self); + node.parent = self; + 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; + + allocator.destroy(self); + + return .{ state, parent }; + } + }; +} |