aboutsummaryrefslogtreecommitdiff
path: root/src/gss.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-05-15 16:54:31 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-05-15 16:54:31 +0200
commit06a216fbabb3e51e32de76e66e2b6f90f9998bd5 (patch)
tree127e4535584ba00e8195ed151e3782ee3f19e704 /src/gss.zig
parent6799a1269e9d095dc6fd2d5354a05488668a76f2 (diff)
improve gss node cashing and creation
Diffstat (limited to 'src/gss.zig')
-rw-r--r--src/gss.zig6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/gss.zig b/src/gss.zig
index ef5d221..9201ca6 100644
--- a/src/gss.zig
+++ b/src/gss.zig
@@ -58,18 +58,22 @@ pub fn Graph(T: type) type {
const Self = @This();
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 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);
node.is_toplevel = true;
@@ -77,6 +81,8 @@ pub fn Graph(T: type) type {
}
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;