From e19219fa0e0a563dfda4a5f00737e0aadd7ca44e Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Fri, 29 Dec 2023 19:33:41 -0800 Subject: [PATCH] std.ComptimeStringMap: allow getting kv index --- lib/std/comptime_string_map.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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;