diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-09-07 14:52:45 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-07 14:52:45 -0400 |
| commit | a48e5af69df17f225cc06658f8a616d54f31d090 (patch) | |
| tree | cf2d4a3e98ea8ea598799a2cac21b1862cb96805 /lib/std | |
| parent | fd2c1d860503ec6cd71ab9a692ad2dbf6bd3c269 (diff) | |
| parent | 5672ee4ed7de11fa3c39ba43619035fdbfc507a5 (diff) | |
| download | zig-a48e5af69df17f225cc06658f8a616d54f31d090.tar.gz zig-a48e5af69df17f225cc06658f8a616d54f31d090.zip | |
Merge pull request #9684 from FnControlOption/astgen-string-table
AstGen: use string index as key for string table
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/hash_map.zig | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig index 765add1e68..644429f871 100644 --- a/lib/std/hash_map.zig +++ b/lib/std/hash_map.zig @@ -92,6 +92,34 @@ pub fn hashString(s: []const u8) u64 { return std.hash.Wyhash.hash(0, s); } +pub const StringIndexContext = struct { + bytes: *std.ArrayListUnmanaged(u8), + + pub fn eql(self: @This(), a: u32, b: u32) bool { + _ = self; + return a == b; + } + + pub fn hash(self: @This(), x: u32) u64 { + const x_slice = mem.spanZ(@ptrCast([*:0]const u8, self.bytes.items.ptr) + x); + return hashString(x_slice); + } +}; + +pub const StringIndexAdapter = struct { + bytes: *std.ArrayListUnmanaged(u8), + + pub fn eql(self: @This(), a_slice: []const u8, b: u32) bool { + const b_slice = mem.spanZ(@ptrCast([*:0]const u8, self.bytes.items.ptr) + b); + return mem.eql(u8, a_slice, b_slice); + } + + pub fn hash(self: @This(), adapted_key: []const u8) u64 { + _ = self; + return hashString(adapted_key); + } +}; + /// Deprecated use `default_max_load_percentage` pub const DefaultMaxLoadPercentage = default_max_load_percentage; |
