fix hashmap using strings as keys

This commit is contained in:
Sahnvour 2019-06-30 20:46:43 +02:00
parent 5bd407b278
commit c9ce43f59f

View File

@ -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