From f37ca349dd5f4844bb2adeedac7fcaec3039a211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Gr=C3=A9goire?= Date: Sat, 1 Aug 2026 19:11:08 -0400 Subject: [PATCH] rcu/hashtable: make init take a struct --- src/rcu/hashtable.zig | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src/rcu/hashtable.zig b/src/rcu/hashtable.zig index e042573..6683dff 100644 --- a/src/rcu/hashtable.zig +++ b/src/rcu/hashtable.zig @@ -147,7 +147,12 @@ const Core = struct { const Self = @This(); - fn init(self: *Self, policy: ResizePolicy, min_size: u32) !void { + fn init( + self: *Self, + smr: *ke.smr.Domain, + policy: ResizePolicy, + min_size: u32, + ) !void { const min: u32 = if (policy == .Compact) @max(2, min_size) else @max(16, min_size); const start_size = min; @@ -174,6 +179,7 @@ const Core = struct { self.rehashing_state = .init(rehashing_none); self.elems = .init(0); + self.smr = smr; self.buckets[0] = .init(@ptrCast(arr)); self.seeds[0] = .init(0); @@ -436,17 +442,28 @@ pub fn Table(comptime T: type, comptime link_field: []const u8, comptime Context _ = obj; unreachable; } + + pub fn is_alive(obj: *T) bool { + _ = obj; + unreachable; + } }); return struct { core: Core, const Self = @This(); + const Options = struct { + smr: *ke.smr.Domain, + policy: ResizePolicy = .Balanced, + min_size: u32 = 0, + }; + /// Initialize a new table, `min_size` provides the minimum count of /// buckets. If `min_size` is 0, it will get clamped to sane defaults /// depending on the chosen policy. - pub fn init(self: *Self, policy: ResizePolicy, min_size: u32) !void { - try self.core.init(policy, min_size); + pub fn init(self: *Self, opts: Options) !void { + try self.core.init(opts.smr, opts.policy, opts.min_size); self.core.hash_link = hash_link; } @@ -511,6 +528,10 @@ pub fn Table(comptime T: type, comptime link_field: []const u8, comptime Context const link: *rcu.SList.Entry = @ptrFromInt(word); const obj = link_to_obj(link); if (Context.eql(Context.key_of(obj), key)) { + // Found it, if it is still alive then return it, otherwise + // replace it. + if (!Context.is_alive(obj)) break; + b.unlock_no_changes(); return obj; }