From 06a216fbabb3e51e32de76e66e2b6f90f9998bd5 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 15 May 2025 16:54:31 +0200 Subject: improve gss node cashing and creation --- src/gss.zig | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/gss.zig') 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; -- cgit v1.2.3-70-g09d2