Interface SuffixTree<O>
- Type Parameters:
O
- The type of the values associated with keys in the tree
- All Known Implementing Classes:
ConcurrentSuffixTree
public interface SuffixTree<O>
API of a generalized suffix tree, that is a tree which allows values to be looked up based on any suffix of the keys
with which they were associated, as well as based on exact matches for keys. A suffix tree essentially allows
"equals", "ends with" and "contains" lookup.
See documentation on each method for details.
-
Method Summary
Modifier and TypeMethodDescriptiongetKeysContaining
(CharSequence fragment) Returns a lazy iterable which returns the set of keys in the tree which contain the given fragment.getKeysEndingWith
(CharSequence suffix) Returns a lazy iterable which returns the set of keys in the tree which end with the given suffix.Returns a lazy iterable which returns the set ofKeyValuePair
s for keys and their associated values in the tree, where the keys contain the given fragment.Returns a lazy iterable which returns the set ofKeyValuePair
s for keys and their associated values in the tree, where the keys end with the given suffix.Returns the value associated with the given key (exact match), or returns null if no such value is associated with the key.getValuesForKeysContaining
(CharSequence fragment) Returns a lazy iterable which returns the set of values associated with keys in the tree which contain the given fragment.Returns a lazy iterable which returns the set of values associated with keys in the tree which end with the given suffix.put
(CharSequence key, O value) Associates the given value with the given key; replacing any previous value associated with the key.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.
-
Method Details
-
put
Associates the given value with the given key; replacing any previous value associated with the key. Returns the previous value associated with the key, if any. This operation is performed atomically.- Parameters:
key
- The key with which the specified value should be associatedvalue
- The value to associate with the key, which cannot be null- Returns:
- The previous value associated with the key, if there was one, otherwise null
-
putIfAbsent
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. This operation is performed atomically.- Parameters:
key
- The key with which the specified value should be associatedvalue
- The value to associate with the key, which cannot be null- Returns:
- The existing value associated with the key, if there was one; otherwise null in which case the new value was successfully associated
-
remove
Removes the value associated with the given key (exact match). If no value is associated with the key, does nothing.- Parameters:
key
- The key for which an associated value should be removed- Returns:
- True if a value was removed (and therefore was associated with the key), false if no value was associated/removed
-
getValueForExactKey
Returns the value associated with the given key (exact match), or returns null if no such value is associated with the key.- Parameters:
key
- The key with which a sought value might be associated- Returns:
- The value associated with the given key (exact match), or null if no value was associated with the key
-
getKeysEndingWith
Returns a lazy iterable which returns the set of keys in the tree which end with the given suffix. This is inclusive - if the given suffix is an exact match for a key in the tree, that key is also returned.- Parameters:
suffix
- A suffix of sought keys in the tree- Returns:
- The set of keys in the tree which end with the given suffix, inclusive
-
getValuesForKeysEndingWith
Returns a lazy iterable which returns the set of values associated with keys in the tree which end with the given suffix. This is inclusive - if the given suffix is an exact match for a key in the tree, the value associated with that key is also returned. Note that although the same value might originally have been associated with multiple keys, or multiple suffixes of the same key, the set returned does not contain duplicates (as determined by the value objects' implementation ofObject.equals(Object)
).- Parameters:
suffix
- A suffix of keys in the tree for which associated values are sought- Returns:
- The set of values associated with keys in the tree which end with the given suffix, inclusive
-
getKeyValuePairsForKeysEndingWith
Returns a lazy iterable which returns the set ofKeyValuePair
s for keys and their associated values in the tree, where the keys end with the given suffix. This is inclusive - if the given suffix is an exact match for a key in the tree, theKeyValuePair
for that key is also returned.- Parameters:
suffix
- A suffix of keys in the tree for which associatedKeyValuePair
s are sought- Returns:
- The set of
KeyValuePair
s for keys in the tree which end with the given suffix, inclusive
-
getKeysContaining
Returns a lazy iterable which returns the set of keys in the tree which contain the given fragment. This is inclusive - if the given fragment is an exact match for a key in the tree, that key is also returned.- Parameters:
fragment
- A fragment of sought keys in the tree- Returns:
- The set of keys in the tree which contain the given fragment, inclusive
-
getValuesForKeysContaining
Returns a lazy iterable which returns the set of values associated with keys in the tree which contain the given fragment. This is inclusive - if the given fragment is an exact match for a key in the tree, the value associated with that key is also returned.- Parameters:
fragment
- A fragment of keys in the tree for which associated values are sought- Returns:
- The set of values associated with keys in the tree which contain the given fragment, inclusive
-
getKeyValuePairsForKeysContaining
Returns a lazy iterable which returns the set ofKeyValuePair
s for keys and their associated values in the tree, where the keys contain the given fragment. This is inclusive - if the given fragment is an exact match for a key in the tree, theKeyValuePair
for that key is also returned.- Parameters:
fragment
- A fragment of keys in the tree for which associatedKeyValuePair
s are sought- Returns:
- The set of
KeyValuePair
s for keys in the tree which contain the given fragment, inclusive
-
size
int size()Counts the number of keys/values stored in the tree. In the current implementation, this has a time complexity similar toConcurrentHashMap.size()
.- Returns:
- The number of keys/values stored in the tree
-