aboutsummaryrefslogtreecommitdiff
path: root/src/gss.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-07-19 20:18:15 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-07-19 20:18:15 +0200
commitae10b7d764d9587ab92a682781f8479107e8dff0 (patch)
tree13e060f304ca1cac98ae1e71a2a6e27d9c5fb269 /src/gss.zig
parentd138a622dcc77302cc452c52946f6202b6a03f5e (diff)
add pex
Diffstat (limited to 'src/gss.zig')
-rw-r--r--src/gss.zig134
1 files changed, 67 insertions, 67 deletions
diff --git a/src/gss.zig b/src/gss.zig
index 12b3b46..aa638a9 100644
--- a/src/gss.zig
+++ b/src/gss.zig
@@ -1,88 +1,88 @@
const std = @import("std");
pub fn Node(T: type) type {
- return struct {
- const Self = @This();
+ return struct {
+ const Self = @This();
- parents: *std.ArrayList(*Self),
- state: T,
+ parents: *std.ArrayList(*Self),
+ state: T,
- pub fn init(state: T, allocator: std.mem.Allocator) !Self {
- const parents = try allocator.create(std.ArrayList(*Self));
- parents.* = std.ArrayList(*Self).init(allocator);
+ pub fn init(state: T, allocator: std.mem.Allocator) !Self {
+ const parents = try allocator.create(std.ArrayList(*Self));
+ parents.* = std.ArrayList(*Self).init(allocator);
- return Self {
- .state = state,
- .parents = parents,
- };
- }
+ return Self {
+ .state = state,
+ .parents = parents,
+ };
+ }
- pub fn clone(self: *Self, state: T) !Self {
- return Self {
- .parents = self.parents,
- .state = state,
- };
- }
+ pub fn clone(self: *Self, state: T) !Self {
+ return Self {
+ .parents = self.parents,
+ .state = state,
+ };
+ }
- pub fn push(self: *Self, state: T) !Self {
- const parents = try self.parents.allocator.create(std.ArrayList(*Self));
- parents.* = std.ArrayList(*Self).init(self.parents.allocator);
- var other = Self {
- .parents = parents,
- .state = state,
- };
+ pub fn push(self: *Self, state: T) !Self {
+ const parents = try self.parents.allocator.create(std.ArrayList(*Self));
+ parents.* = std.ArrayList(*Self).init(self.parents.allocator);
+ var other = Self {
+ .parents = parents,
+ .state = state,
+ };
- try other.parents.append(self);
+ try other.parents.append(self);
- return other;
- }
+ return other;
+ }
- pub fn format(
- self: *const Self,
- comptime fmt: []const u8,
- options: std.fmt.FormatOptions,
- writer: anytype,
- ) !void {
- _ = fmt;
- _ = options;
+ 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});
- }
- };
+ try writer.print("Node {{ {} }}", .{self.state});
+ }
+ };
}
pub fn Graph(T: type) type {
- return struct {
- const Self = @This();
+ return struct {
+ const Self = @This();
- allocator: std.mem.Allocator,
- number_of_nodes: usize = 0,
- number_of_clones: usize = 0,
+ allocator: std.mem.Allocator,
+ number_of_nodes: usize = 0,
+ number_of_clones: usize = 0,
- pub fn init(allocator: std.mem.Allocator) Self {
- return Self { .allocator = allocator };
- }
+ pub fn init(allocator: std.mem.Allocator) Self {
+ return Self { .allocator = allocator };
+ }
- pub fn push(self: *Self, node: *Node(T), state: T) !*Node(T) {
- self.number_of_nodes += 1;
- const child = try self.allocator.create(Node(T));
- child.* = try node.push(state);
- return child;
- }
+ pub fn push(self: *Self, node: *Node(T), state: T) !*Node(T) {
+ self.number_of_nodes += 1;
+ const child = try self.allocator.create(Node(T));
+ child.* = try node.push(state);
+ return child;
+ }
- pub fn add_toplevel(self: *Self, state: T) !*Node(T) {
- self.number_of_nodes += 1;
- const node = try self.allocator.create(Node(T));
- node.* = try Node(T).init(state, self.allocator);
- return node;
- }
+ pub fn add_toplevel(self: *Self, state: T) !*Node(T) {
+ self.number_of_nodes += 1;
+ const node = try self.allocator.create(Node(T));
+ node.* = try Node(T).init(state, self.allocator);
+ return node;
+ }
- pub fn clone(self: *Self, node: *Node(T), state: T) !*Node(T) {
- self.number_of_nodes += 1;
- self.number_of_clones += 1;
- const sibling = try self.allocator.create(Node(T));
- sibling.* = try node.clone(state);
- return sibling;
- }
- };
+ pub fn clone(self: *Self, node: *Node(T), state: T) !*Node(T) {
+ self.number_of_nodes += 1;
+ self.number_of_clones += 1;
+ const sibling = try self.allocator.create(Node(T));
+ sibling.* = try node.clone(state);
+ return sibling;
+ }
+ };
}