Zig 0.17.0-dev (Split by item)

Shortcut keys
?
Show these tips
S
Focus search field
Esc
Clear focus & close tips
U
Jump to source code
↑
Move up in search results
↓
Move down in search results
↵
Go to active search result
This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function

getLongestPrefixIndex

Public Function
std.static_string_map.StaticStringMapWithEql.getLongestPrefixIndex
pub fn getLongestPrefixIndex(self: Self, str: []const u8) ?usize

Returns the index within the generated kvs corresponding to the key-value pair where key is the longest prefix of str, or null if no such key-value pair was found. The returned index is unrelated to the input kvs_list.

This is effectively an O(N) algorithm which loops from max_len to min_len and calls getIndex() to check all keys with the given len.

Params

  • self: Self
  • str: []const u8

File

static_string_map.zig:293
293
294
295
296
297
298
299
300
301
302
303
304
305
306
        pub fn getLongestPrefixIndex(self: Self, str: []const u8) ?usize {
            if (self.kvs.len == 0)
                return null;

            if (str.len < self.min_len)
                return null;

            var len = @min(self.max_len, str.len);
            while (len >= self.min_len) : (len -= 1) {
                if (self.getIndex(str[0..len])) |i|
                    return i;
            }
            return null;
        }