pub fn getLongestPrefixIndex(self: Self, str: []const u8) ?usize self: Selfstr: []const u8293
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;
}
Returns the index within the generated
kvscorresponding to the key-value pair where key is the longest prefix ofstr, ornullif no such key-value pair was found. The returned index is unrelated to the inputkvs_list.This is effectively an O(N) algorithm which loops from
max_lentomin_lenand callsgetIndex()to check all keys with the given len.