K
- type of the sub-keyV
- value to be stored in a leafpublic class PrefixTree<K,V> extends Object
Modifier and Type | Field and Description |
---|---|
protected NodeFactory |
nodeFactory |
protected Node<K,V> |
rootNode |
Constructor and Description |
---|
PrefixTree(NodeFactory nodeFactory,
K key,
V value) |
PrefixTree(NodeFactory nodeFactory,
Node<K,V> rootNode) |
Modifier and Type | Method and Description |
---|---|
void |
add(KeySequence<K> keySequence,
V value)
Adds new value to the trie.
|
Node<K,V> |
find(KeySequence<K> keySequence)
Search for a key
|
Node<K,V> |
findNearest(KeySequence<K> keySequence)
Search as deep as possible and return the deepest node matching a key sequence.
|
Node<K,V> |
findNearestWithValue(KeySequence<K> keySequence)
Search as deep as possible and return the deepest node containing a non-null value matching the keySequence.
|
Node<K,V> |
getRootNode() |
void |
printTree()
Print entire tree to System.out
|
protected Node<K,V> |
rewriteTree(Node<K,V> node,
int depth,
NodeVisitor<K,V> call)
Walk through all the nodes of the prefix tree (including empty intermediate nodes) calling the callback.
|
Node<K,V> |
rewriteTree(Node<K,V> rootNode,
NodeVisitor<K,V> call)
Walk through all the nodes of the prefix tree (including empty intermediate nodes) calling the callback.
|
protected void |
walkTree(Node<K,V> node,
int depth,
NodeVisitor<K,V> call)
Walk through all the nodes of the prefix tree (including empty intermediate nodes) calling the callback.
|
void |
walkTree(Node<K,V> rootNode,
NodeVisitor<K,V> call)
Walk through all the nodes of the prefix tree (including empty intermediate nodes) calling the callback.
|
protected final NodeFactory nodeFactory
public PrefixTree(@NotNull NodeFactory nodeFactory, @NotNull K key, @Nullable V value)
nodeFactory
- for creating new nodesvalue
- value for a root nodepublic PrefixTree(@NotNull NodeFactory nodeFactory, @NotNull Node<K,V> rootNode)
nodeFactory
- for creating new nodesrootNode
- a root nodepublic void add(@NotNull KeySequence<K> keySequence, @Nullable V value)
keySequence
- keyvalue
- value@Nullable public Node<K,V> find(@NotNull KeySequence<K> keySequence)
keySequence
- keynull
if not found@NotNull public Node<K,V> findNearest(@NotNull KeySequence<K> keySequence)
keySequence
- key@Nullable public Node<K,V> findNearestWithValue(@NotNull KeySequence<K> keySequence)
keySequence
- keynull
if no value was not found, even in the root nodepublic void printTree()
public void walkTree(@NotNull Node<K,V> rootNode, @NotNull NodeVisitor<K,V> call)
rootNode
- tree rootcall
- callback methodprotected void walkTree(@NotNull Node<K,V> node, int depth, @NotNull NodeVisitor<K,V> call)
node
- current nodedepth
- depth in tree of the current nodecall
- callback methodpublic Node<K,V> rewriteTree(@NotNull Node<K,V> rootNode, @NotNull NodeVisitor<K,V> call)
rootNode
- tree rootcall
- callback methodprotected Node<K,V> rewriteTree(@NotNull Node<K,V> node, int depth, @NotNull NodeVisitor<K,V> call)
node
- current nodedepth
- depth in tree of the current nodecall
- callback methodCopyright © 2023 OpenClover.org. All rights reserved.