Fix default string hashing mechanism

This commit is contained in:
kayomn 2023-07-12 01:50:18 +01:00
parent 7b266fde58
commit 48f7f97893
1 changed files with 11 additions and 12 deletions

View File

@ -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,
};