Class PrefixSearchTable<K,V>
java.lang.Object
com.google.mu.collect.PrefixSearchTable<K,V>
A lookup table that stores prefix (a list of keys of type
K) -> value mappings.
For example, if the table maps [a, b] prefix to a value "foo", when you search by
[a, b, c], it will find the [a, b] -> foo mapping.
Conceptually it's a "Trie" except it searches by a list of key prefixes instead of string prefixes.
- Since:
- 7.1
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> PrefixSearchTable.Builder <K, V> builder()Returns a new builder.Searches the table for the longest prefix match ofcompoundKey.Searches the table for prefixes ofcompoundKeyand returns a lazy BiStream of all mappings in ascending order of prefix length.Returns a new builder initialized with the same prefix mappings in this table.
-
Method Details
-
get
Searches the table for the longest prefix match ofcompoundKey.- Returns:
- the value mapped to the longest (non-empty) prefix of
compoundKeyif present - Throws:
IllegalArgumentException- ifcompoundKeyis emptyNullPointerException- ifcompoundKeyis null or any key element is null
-
getAll
Searches the table for prefixes ofcompoundKeyand returns a lazy BiStream of all mappings in ascending order of prefix length.If no non-empty prefix exists in the table, an empty BiStream is returned.
To get the longest matched prefix, use
get(java.util.List<? extends K>)instead.- Returns:
- BiStream of the matched prefixes of
compoundKeyand the mapped values - Throws:
IllegalArgumentException- ifcompoundKeyis emptyNullPointerException- ifcompoundKeyis null or any key element is null
-
toBuilder
Returns a new builder initialized with the same prefix mappings in this table.- Since:
- 7.2
-
builder
Returns a new builder.
-