Interface Trie<K,V>
- All Known Implementing Classes:
PatriciaTrie
- Author:
- Roger Kapsi, Sam Berlin
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionReturns a view of thisTrieof all elements that are prefixed by the given key.Returns theMap.Entrywhose key is closest in a bitwise XOR metric to the given key.Iterates through theTrie, starting with the entry whose bitwise value is closest in an XOR metric to the given key.Returns the key that is closest in a bitwise XOR metric to the provided key.selectValue(K key) Returns the value whose key is closest in a bitwise XOR metric to the provided key.Traverses theTriein lexicographical order.Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, equals, forEach, get, getOrDefault, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size
-
Method Details
-
select
Returns theMap.Entrywhose key is closest in a bitwise XOR metric to the given key. This is NOT lexicographic closeness. For example, given the keys:- D = 1000100
- H = 1001000
- L = 1001100
Triecontained 'H' and 'L', a lookup of 'D' would return 'L', because the XOR distance between D & L is smaller than the XOR distance between D & H.- Returns:
- The
Map.Entrywhose key is closest in a bitwise XOR metric to the provided key.
-
selectKey
Returns the key that is closest in a bitwise XOR metric to the provided key. This is NOT lexicographic closeness! For example, given the keys:- D = 1000100
- H = 1001000
- L = 1001100
Triecontained 'H' and 'L', a lookup of 'D' would return 'L', because the XOR distance between D & L is smaller than the XOR distance between D & H.- Returns:
- The key that is closest in a bitwise XOR metric to the provided key.
-
selectValue
Returns the value whose key is closest in a bitwise XOR metric to the provided key. This is NOT lexicographic closeness! For example, given the keys:- D = 1000100
- H = 1001000
- L = 1001100
Triecontained 'H' and 'L', a lookup of 'D' would return 'L', because the XOR distance between D & L is smaller than the XOR distance between D & H.- Returns:
- The value whose key is closest in a bitwise XOR metric to the provided key.
-
select
Iterates through theTrie, starting with the entry whose bitwise value is closest in an XOR metric to the given key. After the closest entry is found, theTriewill call select on that entry and continue calling select for each entry (traversing in order of XOR closeness, NOT lexicographically) until the cursor returnsCursor.Decision.EXIT.The cursor can return
Cursor.Decision.CONTINUEto continue traversing.Cursor.Decision.REMOVE_AND_EXITis used to remove the current element and stop traversing.Note: The
Cursor.Decision.REMOVEoperation is not supported.- Returns:
- The entry the cursor returned
Cursor.Decision.EXITon, or null if it continued till the end.
-
traverse
Traverses theTriein lexicographical order.Cursor.select(java.util.Map.Entry)will be called on each entry.The traversal will stop when the cursor returns
Cursor.Decision.EXIT,Cursor.Decision.CONTINUEis used to continue traversing andCursor.Decision.REMOVEis used to remove the element that was selected and continue traversing.Cursor.Decision.REMOVE_AND_EXITis used to remove the current element and stop traversing.- Returns:
- The entry the cursor returned
Cursor.Decision.EXITon, or null if it continued till the end.
-
prefixMap
Returns a view of thisTrieof all elements that are prefixed by the given key.In a
Triewith fixed size keys, this is essentially aMap.get(Object)operation.For example, if the
Triecontains 'Anna', 'Anael', 'Analu', 'Andreas', 'Andrea', 'Andres', and 'Anatole', then a lookup of 'And' would return 'Andreas', 'Andrea', and 'Andres'.
-