diff options
Diffstat (limited to 'src/rollback.zig')
| -rw-r--r-- | src/rollback.zig | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/rollback.zig b/src/rollback.zig index 7216664c..b0394d22 100644 --- a/src/rollback.zig +++ b/src/rollback.zig @@ -40,11 +40,22 @@ const Pardes = pardes.Pardes; const blob_min = 4096; const checked = builtin.mode == .debug or builtin.mode == .safe; +/// An address as a hash map's key: a multiply, not a Wyhash of its bytes +/// (every allocation of a replica's core is a lookup). +const Addr = struct { + pub fn hash(_: Addr, a: usize) u64 { + return @as(u64, a) *% 0x9e3779b97f4a7c15; + } + pub fn eql(_: Addr, a: usize, b: usize) bool { + return a == b; + } +}; + pub const Epoch = struct { child: Allocator = std.heap.c_allocator, /// Its own bookkeeping, never the epoch's. meta: Allocator = std.heap.c_allocator, - live: std.AutoHashMapUnmanaged(usize, Entry) = .empty, + live: std.HashMapUnmanaged(usize, Entry, Addr, std.hash_map.default_max_load_percentage) = .empty, on: bool = false, id: u32 = 0, born: std.ArrayListUnmanaged(usize) = .empty, @@ -190,7 +201,7 @@ pub const Copy = struct { meta: Allocator = std.heap.c_allocator, regions: std.ArrayListUnmanaged(Region) = .empty, bytes: std.ArrayListUnmanaged(u8) = .empty, - seen: std.AutoHashMapUnmanaged(Seen, void) = .empty, + seen: std.HashMapUnmanaged(Seen, void, SeenContext, std.hash_map.default_max_load_percentage) = .empty, pins: std.ArrayListUnmanaged(Pin) = .empty, held: bool = false, epoch: ?*Epoch = null, @@ -202,6 +213,14 @@ pub const Copy = struct { const Region = struct { addr: usize, off: usize, len: usize }; const Pin = struct { addr: usize, len: usize, hash: u64, where: []const u8 }; const Seen = struct { addr: usize, ty: usize }; + const SeenContext = struct { + pub fn hash(_: SeenContext, k: Seen) u64 { + return (@as(u64, k.addr) *% 0x9e3779b97f4a7c15) ^ (@as(u64, k.ty) *% 0xc2b2ae3d27d4eb4f); + } + pub fn eql(_: SeenContext, a: Seen, b: Seen) bool { + return a.addr == b.addr and a.ty == b.ty; + } + }; pub const Error = Allocator.Error; pub fn deinit(c: *Copy) void { |
