diff options
| author | Meghan Denny <hello@nektro.net> | 2023-12-29 19:33:41 -0800 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2024-01-02 17:40:30 +0200 |
| commit | e19219fa0e0a563dfda4a5f00737e0aadd7ca44e (patch) | |
| tree | 038416f03164a5835be43199694ec804befac78b /lib/std/comptime_string_map.zig | |
| parent | d9d840a33ac8abb0e616de862f592821a7f4a35e (diff) | |
| download | zig-e19219fa0e0a563dfda4a5f00737e0aadd7ca44e.tar.gz zig-e19219fa0e0a563dfda4a5f00737e0aadd7ca44e.zip | |
std.ComptimeStringMap: allow getting kv index
Diffstat (limited to 'lib/std/comptime_string_map.zig')
| -rw-r--r-- | lib/std/comptime_string_map.zig | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/std/comptime_string_map.zig b/lib/std/comptime_string_map.zig index 2c1c260df2..486677e4b3 100644 --- a/lib/std/comptime_string_map.zig +++ b/lib/std/comptime_string_map.zig @@ -103,6 +103,10 @@ pub fn ComptimeStringMapWithEql( /// Returns the value for the key if any, else null. pub fn get(str: []const u8) ?V { + return precomputed.sorted_kvs[getIndex(str) orelse return null].value; + } + + pub fn getIndex(str: []const u8) ?usize { if (str.len < precomputed.min_len or str.len > precomputed.max_len) return null; @@ -112,7 +116,7 @@ pub fn ComptimeStringMapWithEql( if (kv.key.len != str.len) return null; if (eql(kv.key, str)) - return kv.value; + return i; i += 1; if (i >= precomputed.sorted_kvs.len) return null; |
