Module org.eclipse.jgit
Class TernarySearchTree<Value>
java.lang.Object
org.eclipse.jgit.internal.storage.memory.TernarySearchTree<Value>
- Type Parameters:
Value
- type of values in this tree
A ternary search tree with String keys and generic values.
TernarySearchTree is a type of trie (sometimes called a prefix tree) where
nodes are arranged in a manner similar to a binary search tree, but with up
to three children rather than the binary tree's limit of two. Like other
prefix trees, a ternary search tree can be used as an associative map
structure with the ability for incremental string search. However, ternary
search trees are more space efficient compared to standard prefix trees, at
the cost of speed.
Keys must not be null or empty. Values cannot be null.
This class is thread safe.
- Since:
- 6.5
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Loader to load key-value pairs to be cached in the tree -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Remove all key value pairs from this treeboolean
Check whether this tree contains the given key.int
Delete entriesint
Delete a key-value pair.Get the value associated to a key ornull
.getAll()
Get all entries.Get all values.getKeys()
Get all keys.getKeysMatching
(String pattern) Get keys matching given pattern using '?' as wildcard character.getKeysWithPrefix
(String prefix) Get keys starting with given prefixgetLock()
Get the lock guarding read and write access to the cache.getValuesWithPrefix
(String prefix) Get all values with given key prefixgetWithPrefix
(String prefix) Get all entries with given prefixint
Insert a key-value pair.int
Insert map of key-value pairs.keyLongestPrefixOf
(String query) Find the key which is the longest prefix of the given query string.int
Reload the tree entries provided by loaderint
Replace the tree with a new tree containing all entries provided by an iterableint
size()
Get the number of key value pairs in this trie
-
Constructor Details
-
TernarySearchTree
public TernarySearchTree()Construct a new ternary search tree
-
-
Method Details
-
getLock
Get the lock guarding read and write access to the cache.- Returns:
- lock guarding read and write access to the cache
-
replace
Replace the tree with a new tree containing all entries provided by an iterable- Parameters:
loader
- iterable providing key-value pairs to load- Returns:
- number of key-value pairs after replacing finished
-
reload
Reload the tree entries provided by loader- Parameters:
loader
- iterable providing key-value pairs to load- Returns:
- number of key-value pairs
-
delete
Delete entries- Parameters:
delete
- iterable providing keys of entries to be deleted- Returns:
- number of key-value pairs
-
size
public int size()Get the number of key value pairs in this trie- Returns:
- number of key value pairs in this trie
-
get
Get the value associated to a key ornull
.- Parameters:
key
- the key- Returns:
- the value associated to this key
-
contains
Check whether this tree contains the given key.- Parameters:
key
- a key- Returns:
- whether this tree contains this key
-
insert
Insert a key-value pair. If the key already exists the old value is overwritten.- Parameters:
key
- the keyvalue
- the value- Returns:
- number of key-value pairs after adding the entry
-
insert
Insert map of key-value pairs. Values of existing keys are overwritten. Use this method to insert multiple key-value pairs.- Parameters:
map
- map of key-value pairs to insert- Returns:
- number of key-value pairs after adding entries
-
delete
Delete a key-value pair. Does nothing if the key doesn't exist.- Parameters:
key
- the key- Returns:
- number of key-value pairs after the deletion
-
clear
public void clear()Remove all key value pairs from this tree -
keyLongestPrefixOf
Find the key which is the longest prefix of the given query string.- Parameters:
query
- the query string- Returns:
- the key which is the longest prefix of the given query string or
null
if none exists.
-
getKeys
Get all keys.- Returns:
- all keys
-
getKeysWithPrefix
Get keys starting with given prefix- Parameters:
prefix
- key prefix- Returns:
- keys starting with given prefix
-
getAll
Get all entries.- Returns:
- all entries
-
getAllValues
Get all values.- Returns:
- all values
-
getWithPrefix
Get all entries with given prefix- Parameters:
prefix
- key prefix- Returns:
- entries with given prefix
-
getValuesWithPrefix
Get all values with given key prefix- Parameters:
prefix
- key prefix- Returns:
- entries with given prefix
-
getKeysMatching
Get keys matching given pattern using '?' as wildcard character.- Parameters:
pattern
- search pattern- Returns:
- keys matching given pattern.
-