diff options
Diffstat (limited to 'src/bun.zig')
-rw-r--r-- | src/bun.zig | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/bun.zig b/src/bun.zig index 13137eab6..92b8ff2b3 100644 --- a/src/bun.zig +++ b/src/bun.zig @@ -506,3 +506,38 @@ pub fn getenvZ(path_: [:0]const u8) ?[]const u8 { const ptr = std.c.getenv(path_.ptr) orelse return null; return span(ptr); } + +// These wrappers exist to use our strings.eqlLong function +pub const StringArrayHashMapContext = struct { + pub fn hash(_: @This(), s: []const u8) u32 { + return @truncate(u32, std.hash.Wyhash.hash(0, s)); + } + pub fn eql(_: @This(), a: []const u8, b: []const u8, _: usize) bool { + return strings.eqlLong(a, b, true); + } +}; + +pub const StringHashMapContext = struct { + pub fn hash(_: @This(), s: []const u8) u64 { + return std.hash.Wyhash.hash(0, s); + } + pub fn eql(_: @This(), a: []const u8, b: []const u8) bool { + return strings.eqlLong(a, b, true); + } +}; + +pub fn StringArrayHashMap(comptime Type: type) type { + return std.ArrayHashMap([]const u8, Type, StringArrayHashMapContext, true); +} + +pub fn StringArrayHashMapUnmanaged(comptime Type: type) type { + return std.ArrayHashMapUnmanaged([]const u8, Type, StringArrayHashMapContext, true); +} + +pub fn StringHashMap(comptime Type: type) type { + return std.HashMap([]const u8, Type, StringHashMapContext, std.hash_map.default_max_load_percentage); +} + +pub fn StringHashMapUnmanaged(comptime Type: type) type { + return std.HashMapUnmanaged([]const u8, Type, StringHashMapContext, std.hash_map.default_max_load_percentage); +} |