From cf4d53c3eb35028839e6b267230c23df68b1e94a Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Sat, 26 Apr 2025 14:23:28 +0200 Subject: first working implementation (unoptimized) --- src/gss.zig | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/gss.zig (limited to 'src/gss.zig') 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 }; + } + }; +} -- cgit v1.2.3-70-g09d2