Modifier and Type | Interface and Description |
---|---|
static interface |
Trie.Cursor<K,V>
An interface used by a
Trie . |
Modifier and Type | Method and Description |
---|---|
SortedMap<K,V> |
getPrefixedBy(K key)
Returns a view of this Trie of all elements that are
prefixed by the given key.
|
SortedMap<K,V> |
getPrefixedBy(K key,
int length)
Returns a view of this Trie of all elements that are
prefixed by the length of the key.
|
SortedMap<K,V> |
getPrefixedBy(K key,
int offset,
int length)
Returns a view of this Trie of all elements that are prefixed
by the key, starting at the given offset and for the given length.
|
SortedMap<K,V> |
getPrefixedByBits(K key,
int bitLength)
Returns a view of this Trie of all elements that are prefixed
by the number of bits in the given Key.
|
V |
select(K key)
Returns the value for the entry whose key is closest in a bitwise
XOR metric to the given key.
|
Map.Entry<K,V> |
select(K key,
Trie.Cursor<? super K,? super V> cursor)
Iterates through the Trie, starting with the entry whose bitwise
value is closest in an XOR metric to the given key.
|
Map.Entry<K,V> |
traverse(Trie.Cursor<? super K,? super V> cursor)
Traverses the Trie in lexicographical order.
|
comparator, entrySet, firstKey, headMap, keySet, lastKey, subMap, tailMap, values
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size
SortedMap<K,V> getPrefixedBy(K key)
In a fixed-keysize Trie, this is essentially a 'get' operation.
For example, if the Trie contains 'Lime', 'LimeWire', 'LimeRadio', 'Lax', 'Later', 'Lake', and 'Lovely', then a lookup of 'Lime' would return 'Lime', 'LimeRadio', and 'LimeWire'.
key
- Key to search for within the trie.Map
containing keys matching the given prefix and their
values.SortedMap<K,V> getPrefixedBy(K key, int length)
Fixed-keysize Tries will not support this operation (because all keys will be the same length).
For example, if the Trie contains 'Lime', 'LimeWire', 'LimeRadio', 'Lax', 'Later', 'Lake', and 'Lovely', then a lookup of 'LimePlastics' with a length of 4 would return 'Lime', 'LimeRadio', and 'LimeWire'.
key
- Key to search for within the trie.length
- Length of key
. Ignored for tries with a fixed key
size.Map
containing keys matching the given prefix and their
values.SortedMap<K,V> getPrefixedBy(K key, int offset, int length)
Fixed-keysize Tries will not support this operation (because all keys are the same length).
For example, if the Trie contains 'Lime', 'LimeWire', 'LimeRadio', 'Lax', 'Later', 'Lake', and 'Lovely', then a lookup of 'The Lime Plastics' with an offset of 4 and a length of 4 would return 'Lime', 'LimeRadio', and 'LimeWire'.
key
- Key to search for within the trie.offset
- Offset to begin search at.length
- Length of key
. Ignored for tries with a fixed key
size.Map
containing keys matching the given prefix and their
values.SortedMap<K,V> getPrefixedByBits(K key, int bitLength)
Fixed-keysize Tries can support this operation as a way to do lookups of partial keys. That is, if the Trie is storing IP addresses, you can lookup all addresses that begin with '192.168' by providing the key '192.168.X.X' and a length of 16 would return all addresses that begin with '192.168'.
key
- Key to search for within the trie.bitLength
- Length of key
in bits.Map
containing keys matching the given prefix and their
values.V select(K key)
If the Trie contained 'H' and 'L', a lookup of 'D' would return 'L', because the XOR distance between D and L is smaller than the XOR distance between D and H.
key
- Key to search for within the trie.key
.Map.Entry<K,V> select(K key, Trie.Cursor<? super K,? super V> cursor)
Cursor.SelectStatus.EXIT
.Cursor.SelectStatus.CONTINUE
to
continue traversing.Cursor.SelectStatus.REMOVE_AND_EXIT
is used to remove the current element
and stop traversing.
Note: The Trie.Cursor.SelectStatus.REMOVE
operation is not supported.
key
- Key to match.cursor
- Cursor being used to traverse the trie.Map.Entry<K,V> traverse(Trie.Cursor<? super K,? super V> cursor)
Cursor.select
will be called on each entry.
The traversal will stop when the cursor returns Cursor.SelectStatus.EXIT
.
Cursor.SelectStatus.CONTINUE
is used to continue traversing.
Cursor.SelectStatus.REMOVE
is used to remove the element that was
selected and continue traversing.
Cursor.SelectStatus.REMOVE_AND_EXIT
is used to remove the current element
and stop traversing.
cursor
- Cursor being used to traverse the trie.