diff --git a/src/core/ByteMap.zig b/src/core/ByteMap.zig index 75df821..0fbdf61 100644 --- a/src/core/ByteMap.zig +++ b/src/core/ByteMap.zig @@ -39,6 +39,7 @@ table: []Entry, table_size: usize, var collisions: usize = 0; +var hasher = Wyhash.init(0); pub fn init(self: *ByteMap, allocator: *Mmap, size_arg: usize) !void { self.table_size = try std.math.ceilPowerOfTwo(usize, size_arg); @@ -57,7 +58,7 @@ pub fn init(self: *ByteMap, allocator: *Mmap, size_arg: usize) !void { } fn get_index(self: *ByteMap, key: []const u8) usize { - return std.hash.Wyhash.hash(@intCast(key.len), key) & (self.table_size - 1); + return hasher.reset_hash(@intCast(key.len), key) & (self.table_size - 1); } fn find_entry(self: *ByteMap, key: []const u8, comptime insertion: bool) ?*Entry { diff --git a/src/core/Wyhash.zig b/src/core/Wyhash.zig index 6ff6c75..f8a7671 100644 --- a/src/core/Wyhash.zig +++ b/src/core/Wyhash.zig @@ -194,6 +194,17 @@ pub fn hash(self: *Wyhash, input: []const u8) u64 { return self.final2(); } +pub fn reset_hash(self: *Wyhash, seed: u64, input: []const u8) u64 { + self.total_len = 0; + self.buf_len = 0; + + self.state[0] = seed ^ mix(seed ^ secret[0], secret[1]); + self.state[1] = self.state[0]; + self.state[2] = self.state[0]; + + return self.hash(input); +} + pub fn reset(self: *Wyhash) void { self.total_len = 0; self.buf_len = 0;