aboutsummaryrefslogtreecommitdiff
path: root/src/gss.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/gss.zig')
-rw-r--r--src/gss.zig30
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 };
+ }
+ };
+}