From 48f7f97893500ca7e6c21e8e099d7fce11e73a0b Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 12 Jul 2023 01:50:18 +0100 Subject: [PATCH] Fix default string hashing mechanism --- source/coral/map.zig | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/source/coral/map.zig b/source/coral/map.zig index 875d1e6..7dbb777 100644 --- a/source/coral/map.zig +++ b/source/coral/map.zig @@ -287,18 +287,17 @@ pub fn TableTraits(comptime Key: type) type { }; } +fn hash_string(key: []const io.Byte) usize { + var hash_code = @as(usize, 5381); + + for (key) |byte| { + hash_code = ((hash_code << 5) +% hash_code) +% byte; + } + + return hash_code; +} + pub const string_table_traits = TableTraits([]const io.Byte){ - .hash = struct { - fn hash(key: []const io.Byte) usize { - var hash_code = @as(usize, 5381); - - for (key) |byte| { - hash_code = ((hash_code << 5) + hash_code) + byte; - } - - return hash_code; - } - }.hash, - + .hash = hash_string, .match = io.equals, };