Class AbstractTrieMap<K,V,S>
- Type Parameters:
K
- the key type.V
- the value type that this holds.S
- the type of the split segments used for searching.
- Direct Known Subclasses:
StringTrieMap
- Author:
- Matthew Tropiano
-
Nested Class Summary
Nested classes/interfaces inherited from class net.mtrop.doom.struct.trie.AbstractTrie
AbstractTrie.Node<V,
S>, AbstractTrie.Result<V, S>, AbstractTrie.TrieIterator<V, S> -
Field Summary
Fields inherited from class net.mtrop.doom.struct.trie.AbstractTrie
root
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
containsKey
(K key) Checks if an object (by equality) is present in the structure.protected final boolean
Determines if the objects are equal.protected boolean
equalityMethodForKey
(K key1, K key2) Determines if two keys are equal.Returns a value for the key provided.int
getAfterKey
(K key, List<V> out) Returns all values descending from the end of a search for a particular key.int
getAfterKey
(K key, List<V> out, int startOffset) Returns all values descending from the end of a search for a particular value.int
getBeforeKey
(K key, List<V> out) Returns all values in the order that they are found on the way through the Trie searching for a particular corresponding value.int
getBeforeKey
(K key, List<V> out, int startOffset) Returns all values in the order that they are found on the way through the Trie searching for a particular corresponding value.int
getKeysAfterKey
(K key, List<K> out) Returns all keys descending from the end of a search for a particular key.int
getKeysAfterKey
(K key, List<K> out, int startOffset) Returns all keys descending from the end of a search for a particular key.int
getKeysBeforeKey
(K key, List<K> out) Returns all keys in the order that they are found on the way through the Trie searching for a particular matching key.int
getKeysBeforeKey
(K key, List<K> out, int startOffset) Returns all keys in the order that they are found on the way through the Trie searching for a particular matching key.getKeyWithRemainderByKey
(K key, List<S> out) Returns the last-encountered key down a trie search, plus the remainder of the segments generated by the key from the last-matched segment.getKeyWithRemainderByKey
(K key, List<S> out, int startOffset) Returns the last-encountered key down a trie search, plus the remainder of the segments generated by the key from the last-matched segment.protected final S[]
getSegments
(Map.Entry<K, V> pair) Creates the segments necessary to find/store values.protected abstract S[]
getSegmentsForKey
(K key) Creates the segments necessary to find/store values with keys.getWithRemainderByKey
(K key, List<S> out) Returns the last-encountered value down a trie search.getWithRemainderByKey
(K key, List<S> out, int startOffset) Returns the last-encountered value down a trie search.void
Associates a key to a value in this map.removeEntry
(K key) Removes a value from this map, corresponding to a key.protected AbstractTrie.Result<Map.Entry<K,
V>, S> searchByKey
(K key, boolean includeEncountered, boolean includeDescendants) Search using a key.void
toArrayKeys
(K[] out) Copies the keys of this map into an array.void
toArrayValues
(V[] out) Copies the values of this map into an array.Methods inherited from class net.mtrop.doom.struct.trie.AbstractTrie
add, clear, contains, getAfter, getAfter, getBefore, getBefore, getWithRemainder, getWithRemainder, isEmpty, iterator, remove, search, size, toArray
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
AbstractTrieMap
public AbstractTrieMap()Creates a new trie map.
-
-
Method Details
-
getSegments
Description copied from class:AbstractTrie
Creates the segments necessary to find/store values. This should always create the same segments for the same value.- Specified by:
getSegments
in classAbstractTrie<Map.Entry<K,
V>, S> - Parameters:
pair
- the value to generate significant segments for.- Returns:
- the list of segments for the value.
-
getSegmentsForKey
Creates the segments necessary to find/store values with keys. This should always create the same segments for the same key.- Parameters:
key
- the key to generate significant segments for.- Returns:
- the list of segments for the key.
-
put
Associates a key to a value in this map. The policy of "put" is that if it an object already in the set, its value is replaced with the new value.- Parameters:
key
- the map key.value
- the corresponding value.- See Also:
-
containsKey
Checks if an object (by equality) is present in the structure.- Parameters:
key
- the object to use for checking presence.- Returns:
- true if it is in the map, false otherwise.
-
get
Returns a value for the key provided.- Parameters:
key
- the key.- Returns:
- the corresponding value, or null if there is no value associated with that key.
-
getBeforeKey
Returns all values in the order that they are found on the way through the Trie searching for a particular corresponding value. Result may include the value corresponding to the key.The results are set in the output list provided by the user - an offset before the end of the list replaces, not adds!
- Parameters:
key
- the key to search for.out
- the output list.- Returns:
- the amount of items returned into the list.
-
getBeforeKey
Returns all values in the order that they are found on the way through the Trie searching for a particular corresponding value. Result may include the value corresponding to the key.The results are set in the output list provided by the user - an offset before the end of the list replaces, not adds!
- Parameters:
key
- the key to search for.out
- the output list.startOffset
- the starting offset into the list to set values.- Returns:
- the amount of items returned into the list.
-
getAfterKey
Returns all values descending from the end of a search for a particular key. Result may include the value corresponding to the key.The values returned may not be returned in any consistent or stable order.
The results are added to the end of the list.
- Parameters:
key
- the key to search for.out
- the output list.- Returns:
- the amount of items returned into the list.
-
getAfterKey
Returns all values descending from the end of a search for a particular value. Result may include the value corresponding to the key.The values returned may not be returned in any consistent or stable order.
The results are set in the output list provided by the user - an offset before the end of the list replaces, not adds!
- Parameters:
key
- the key to search for.out
- the output list.startOffset
- the starting offset into the list to set values.- Returns:
- the amount of items returned into the list.
-
getWithRemainderByKey
Returns the last-encountered value down a trie search. This is the remainder of the segments generated by the key from the last-matched segment.- Parameters:
key
- the key to search for.out
- the output list.- Returns:
- the last-encountered value.
-
getWithRemainderByKey
Returns the last-encountered value down a trie search. This is the remainder of the segments generated by the key from the last-matched segment.- Parameters:
key
- the key to search for.out
- the output list.startOffset
- the starting offset into the list to set values.- Returns:
- the last-encountered value, or null if none encountered.
-
getKeysBeforeKey
Returns all keys in the order that they are found on the way through the Trie searching for a particular matching key. Result may include the provided key.The results are set in the output list provided by the user - an offset before the end of the list replaces, not adds!
- Parameters:
key
- the key to search for.out
- the output list.- Returns:
- the amount of items returned into the list.
-
getKeysBeforeKey
Returns all keys in the order that they are found on the way through the Trie searching for a particular matching key. Result may include the the provided key.The results are set in the output list provided by the user - an offset before the end of the list replaces, not adds!
- Parameters:
key
- the key to search for.out
- the output list.startOffset
- the starting offset into the list to set keys.- Returns:
- the amount of items returned into the list.
-
getKeysAfterKey
Returns all keys descending from the end of a search for a particular key. Result may include the provided key.The keys returned may not be returned in any consistent or stable order.
The results are added to the end of the list.
- Parameters:
key
- the key to search for.out
- the output list.- Returns:
- the amount of items returned into the list.
-
getKeysAfterKey
Returns all keys descending from the end of a search for a particular key. Result may include the provided key.The keys returned may not be returned in any consistent or stable order.
The results are set in the output list provided by the user - an offset before the end of the list replaces, not adds!
- Parameters:
key
- the key to search for.out
- the output list.startOffset
- the starting offset into the list to set keys.- Returns:
- the amount of items returned into the list.
-
getKeyWithRemainderByKey
Returns the last-encountered key down a trie search, plus the remainder of the segments generated by the key from the last-matched segment.- Parameters:
key
- the key to search for.out
- the output list.- Returns:
- the last-encountered value.
-
getKeyWithRemainderByKey
Returns the last-encountered key down a trie search, plus the remainder of the segments generated by the key from the last-matched segment.- Parameters:
key
- the key to search for.out
- the output list.startOffset
- the starting offset into the list to set keys.- Returns:
- the last-encountered value.
-
searchByKey
protected AbstractTrie.Result<Map.Entry<K,V>, searchByKeyS> (K key, boolean includeEncountered, boolean includeDescendants) Search using a key.- Parameters:
key
- the key to search for.includeEncountered
- if true, include all visited nodes in the result.includeDescendants
- if true, include all descendants after the ending node in the result.- Returns:
- the result of the search.
-
removeEntry
Removes a value from this map, corresponding to a key.- Parameters:
key
- the key to use for checking presence.- Returns:
- the corresponding value if it was removed from the map, null otherwise.
-
toArrayKeys
Copies the keys of this map into an array. The order of the contents are not guaranteed unless otherwise noted.- Parameters:
out
- the target array to copy the key objects into.- Throws:
ArrayIndexOutOfBoundsException
- if the target array is too small to contain the objects.- See Also:
-
toArrayValues
Copies the values of this map into an array. Values are not distinct - if more than one value is in this map, it is added as well. The order of the contents are not guaranteed unless otherwise noted.- Parameters:
out
- the target array to copy the key objects into.- Throws:
ArrayIndexOutOfBoundsException
- if the target array is too small to contain the objects.- See Also:
-
equalityMethod
Description copied from class:AbstractTrie
Determines if the objects are equal. This can be implemented differently in case a data structure has a different concept of what is considered equal.- Overrides:
equalityMethod
in classAbstractTrie<Map.Entry<K,
V>, S> - Parameters:
object1
- the first object.object2
- the second object.- Returns:
- true if the keys are considered equal, false otherwise.
-
equalityMethodForKey
Determines if two keys are equal. This can be implemented differently in case a map has a different concept of what keys are considered equal.- Parameters:
key1
- the first key.key2
- the second key.- Returns:
- true if the keys are considered equal, false otherwise.
-