implementing hash tables (ch20)

This commit is contained in:
mycroft committed 2024-08-26 16:43:20 +02:00
1 parent b0414bbe7b
commit df9d1079ea
7 files changed
+384 -17

No files matched your search

+11
View File
@@ -24,3 +24,14 @@ pub fn constant_instruction(opcode_name: []const u8, chunk: Chunk, offset: usize
debug.print("'\n", .{});
return offset + 2;
}
pub fn compute_hash(str: []const u8) u32 {
var res_hash: u32 = 2166136261;
for (str) |c| {
res_hash ^= c;
res_hash *%= 16777619;
}
return res_hash;
}