commit c9ce43f59fc777055612aeea58db0849390bc204 (tree)
parent 5bd407b27890fbed82891289e6a2bf2da93c2a41
Author: Sahnvour <sahnvour@pm.me>
Date: Sun, 30 Jun 2019 20:46:43 +0200
fix hashmap using strings as keys
Diffstat:
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/std/http/headers.zig b/std/http/headers.zig
@@ -102,9 +102,19 @@ test "HeaderEntry" {
testing.expectEqualSlices(u8, "x", e.value);
}
+fn stringEql(a: []const u8, b: []const u8) bool {
+ if (a.len != b.len) return false;
+ if (a.ptr == b.ptr) return true;
+ return mem.compare(u8, a, b) == .Equal;
+}
+
+fn stringHash(s: []const u8) u32 {
+ return @truncate(u32, std.hash.wyhash(s, 0));
+}
+
const HeaderList = std.ArrayList(HeaderEntry);
const HeaderIndexList = std.ArrayList(usize);
-const HeaderIndex = std.AutoHashMap([]const u8, HeaderIndexList);
+const HeaderIndex = std.HashMap([]const u8, HeaderIndexList, stringHash, stringEql);
pub const Headers = struct {
// the owned header field name is stored in the index as part of the key