initComptime
Returns a map backed by static, comptime allocated memory.
kvs_list must be either a list of struct { []const u8, V }
(key-value pair) tuples, or a list of struct { []const u8 }
(only keys) tuples if V is void.
Function parameters
Parameters
- kvs_list:anytype
Static string map optimized for small sets of disparate string keys.
Functions
- StaticStringMap
- Static string map optimized for small sets of disparate string keys.
- defaultEql
- Like `std.mem.eql`, but takes advantage of the fact that the lengths
- eqlAsciiIgnoreCase
- Like `std.ascii.eqlIgnoreCase` but takes advantage of the fact that
- StaticStringMapWithEql
- StaticStringMap, but accepts an equality function (`eql`).
Source
Implementation
pub inline fn initComptime(comptime kvs_list: anytype) Self {
comptime {
var self = Self{};
if (kvs_list.len == 0)
return self;
// Since the KVs are sorted, a linearly-growing bound will never
// be sufficient for extreme cases. So we grow proportional to
// N*log2(N).
@setEvalBranchQuota(10 * kvs_list.len * std.math.log2_int_ceil(usize, kvs_list.len));
var sorted_keys: [kvs_list.len][]const u8 = undefined;
var sorted_vals: [kvs_list.len]V = undefined;
self.initSortedKVs(kvs_list, &sorted_keys, &sorted_vals);
const final_keys = sorted_keys;
const final_vals = sorted_vals;
self.kvs = &.{
.keys = &final_keys,
.values = &final_vals,
.len = @intCast(kvs_list.len),
};
var len_indexes: [self.max_len + 1]u32 = undefined;
self.initLenIndexes(&len_indexes);
const final_len_indexes = len_indexes;
self.len_indexes = &final_len_indexes;
self.len_indexes_len = @intCast(len_indexes.len);
return self;
}
}