public class ConcurrentInvertedRadixTree<O> extends Object implements InvertedRadixTree<O>, PrettyPrintable, Serializable
InvertedRadixTree which supports lock-free concurrent reads, and allows items to be
added to and to be removed from the tree atomically by background thread(s), without blocking reads.
This implementation is based on ConcurrentRadixTree.| Constructor and Description |
|---|
ConcurrentInvertedRadixTree(NodeFactory nodeFactory)
Creates a new
ConcurrentInvertedRadixTree which will use the given NodeFactory to create nodes. |
| Modifier and Type | Method and Description |
|---|---|
Iterable<CharSequence> |
getClosestKeys(CharSequence candidate)
Returns a lazy iterable which returns the set of keys in the tree which are the closest match for the given
candidate key.
|
Iterable<CharSequence> |
getKeysContainedIn(CharSequence document)
Returns a lazy iterable which returns the set of keys in the tree which are contained in the given document.
|
Iterable<CharSequence> |
getKeysPrefixing(CharSequence document)
Returns a lazy iterable which returns the set of keys in the tree which prefix the given document.
|
Iterable<CharSequence> |
getKeysStartingWith(CharSequence prefix)
Returns a lazy iterable which returns the set of keys in the tree which start with the given prefix.
|
KeyValuePair<O> |
getKeyValuePairForLongestKeyPrefixing(CharSequence document)
Returns the
KeyValuePair for the longest key in the tree which is a prefix of the given document. |
Iterable<KeyValuePair<O>> |
getKeyValuePairsForClosestKeys(CharSequence candidate)
Returns a lazy iterable which returns the set of
KeyValuePairs for keys and their associated values in
the tree which are the closest match for the given candidate key. |
Iterable<KeyValuePair<O>> |
getKeyValuePairsForKeysContainedIn(CharSequence document)
Returns a lazy iterable which returns the set of
KeyValuePairs for keys in the tree which are contained
in the given document. |
Iterable<KeyValuePair<O>> |
getKeyValuePairsForKeysPrefixing(CharSequence document)
Returns a lazy iterable which returns the set of
KeyValuePairs for keys in the tree which prefix
the given document. |
Iterable<KeyValuePair<O>> |
getKeyValuePairsForKeysStartingWith(CharSequence prefix)
Returns a lazy iterable which returns the set of
KeyValuePairs for keys and their associated values
in the tree, where the keys start with the given prefix. |
CharSequence |
getLongestKeyPrefixing(CharSequence document)
Returns the longest key in the tree which is a prefix of the given document.
|
Node |
getNode() |
O |
getValueForExactKey(CharSequence key)
Returns the value associated with the given key (exact match), or returns null if no such value
is associated with the key.
|
O |
getValueForLongestKeyPrefixing(CharSequence document)
Returns the value associated with the longest key in the tree which is a prefix of the given document.
|
Iterable<O> |
getValuesForClosestKeys(CharSequence candidate)
Returns a lazy iterable which returns the set of values associated with keys in the tree which are the closest
match for the given candidate key.
|
Iterable<O> |
getValuesForKeysContainedIn(CharSequence document)
Returns a lazy iterable which returns the set of values associated with keys in the tree which are contained
in the given document.
|
Iterable<O> |
getValuesForKeysPrefixing(CharSequence document)
Returns a lazy iterable which returns the set of values associated with keys in the tree which prefix
the given document.
|
Iterable<O> |
getValuesForKeysStartingWith(CharSequence prefix)
Returns a lazy iterable which returns the set of values associated with keys in the tree which start with the
given prefix.
|
O |
put(CharSequence key,
O value)
Associates the given value with the given key; replacing any previous value associated with the key.
|
O |
putIfAbsent(CharSequence key,
O value)
If a value is not already associated with the given key in the tree, associates the given value with the
key; otherwise if an existing value is already associated, returns the existing value and does not overwrite it.
|
boolean |
remove(CharSequence key)
Removes the value associated with the given key (exact match).
|
int |
size()
Counts the number of keys/values stored in the tree.
|
public ConcurrentInvertedRadixTree(NodeFactory nodeFactory)
ConcurrentInvertedRadixTree which will use the given NodeFactory to create nodes.nodeFactory - An object which creates Node objects on-demand, and which might return node
implementations optimized for storing the values supplied to it for the creation of each nodepublic O put(CharSequence key, O value)
put in interface RadixTree<O>put in interface InvertedRadixTree<O>key - The key with which the specified value should be associatedvalue - The value to associate with the key, which cannot be nullpublic O putIfAbsent(CharSequence key, O value)
putIfAbsent in interface RadixTree<O>putIfAbsent in interface InvertedRadixTree<O>key - The key with which the specified value should be associatedvalue - The value to associate with the key, which cannot be nullpublic boolean remove(CharSequence key)
public O getValueForExactKey(CharSequence key)
getValueForExactKey in interface RadixTree<O>getValueForExactKey in interface InvertedRadixTree<O>key - The key with which a sought value might be associatedpublic Iterable<CharSequence> getKeysStartingWith(CharSequence prefix)
getKeysStartingWith in interface RadixTree<O>prefix - A prefix of sought keys in the treepublic Iterable<O> getValuesForKeysStartingWith(CharSequence prefix)
Object.equals(Object)).getValuesForKeysStartingWith in interface RadixTree<O>prefix - A prefix of keys in the tree for which associated values are soughtpublic Iterable<KeyValuePair<O>> getKeyValuePairsForKeysStartingWith(CharSequence prefix)
KeyValuePairs for keys and their associated values
in the tree, where the keys start with the given prefix.
This is inclusive - if the given prefix is an exact match for a key in the tree, the KeyValuePair
for that key is also returned.getKeyValuePairsForKeysStartingWith in interface RadixTree<O>prefix - A prefix of keys in the tree for which associated KeyValuePairs are soughtKeyValuePairs for keys in the tree which start with the given prefix, inclusivepublic Iterable<CharSequence> getClosestKeys(CharSequence candidate)
Ford Focus, Ford Mondeo, BMW M3getClosestKeys("Ford F150") -> returns Ford Focus, Ford MondeogetClosestKeys in interface RadixTree<O>candidate - A candidate keypublic Iterable<O> getValuesForClosestKeys(CharSequence candidate)
getValuesForClosestKeys in interface RadixTree<O>candidate - A candidate keypublic Iterable<KeyValuePair<O>> getKeyValuePairsForClosestKeys(CharSequence candidate)
KeyValuePairs for keys and their associated values in
the tree which are the closest match for the given candidate key.
See {#getClosestKeys} for more details.getKeyValuePairsForClosestKeys in interface RadixTree<O>candidate - A candidate keyKeyValuePairs for keys and their associated values in the tree which most closely
match the candidate key, inclusivepublic Iterable<CharSequence> getKeysPrefixing(CharSequence document)
getKeysPrefixing in interface InvertedRadixTree<O>document - A document to be scanned for keys contained in the tree which prefix the given documentpublic Iterable<O> getValuesForKeysPrefixing(CharSequence document)
getValuesForKeysPrefixing in interface InvertedRadixTree<O>document - A document to be scanned for keys contained in the tree which prefix the given documentpublic Iterable<KeyValuePair<O>> getKeyValuePairsForKeysPrefixing(CharSequence document)
KeyValuePairs for keys in the tree which prefix
the given document.getKeyValuePairsForKeysPrefixing in interface InvertedRadixTree<O>document - A document to be scanned for keys contained in the tree which prefix the given documentKeyValuePairs for keys in the tree which prefix the given documentpublic CharSequence getLongestKeyPrefixing(CharSequence document)
getLongestKeyPrefixing in interface InvertedRadixTree<O>document - A document to be scanned for a key contained in the tree which prefixes the given documentpublic O getValueForLongestKeyPrefixing(CharSequence document)
getValueForLongestKeyPrefixing in interface InvertedRadixTree<O>document - A document to be scanned for a key contained in the tree which prefixes the given documentpublic KeyValuePair<O> getKeyValuePairForLongestKeyPrefixing(CharSequence document)
KeyValuePair for the longest key in the tree which is a prefix of the given document.getKeyValuePairForLongestKeyPrefixing in interface InvertedRadixTree<O>document - A document to be scanned for a key contained in the tree which prefixes the given documentKeyValuePair for the longest key in the tree which is a prefix of the given document,
or null if no such key is contained in the treepublic Iterable<CharSequence> getKeysContainedIn(CharSequence document)
getKeysContainedIn in interface InvertedRadixTree<O>document - A document to be scanned for keys contained in the treepublic Iterable<O> getValuesForKeysContainedIn(CharSequence document)
getValuesForKeysContainedIn in interface InvertedRadixTree<O>document - A document to be scanned for keys contained in the treepublic Iterable<KeyValuePair<O>> getKeyValuePairsForKeysContainedIn(CharSequence document)
KeyValuePairs for keys in the tree which are contained
in the given document.getKeyValuePairsForKeysContainedIn in interface InvertedRadixTree<O>document - A document to be scanned for keys contained in the treeKeyValuePairs for keys in the tree which are contained in the given documentpublic int size()
public Node getNode()
getNode in interface PrettyPrintableCopyright © 2017. All Rights Reserved.