T - payload data typepublic class Trie<T extends Serializable> extends Object implements PrefixDictionary<T>
| Constructor and Description |
|---|
Trie()
Create empty trie.
|
Trie(TrieNode<T> root)
Create a trie with an existing root node.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Clear all contained words and playload data.
|
boolean |
contains(char[] word)
Check if a word is included exactly in the trie.
|
boolean |
containsPrefix(char[] word)
Check if a word is either included completely or as prefix in the trie.
|
void |
delete(char[] word)
Delete the data associated with the given word.
|
T |
getData(char[] word)
Get data associated with the word in the trie, or null if the word was
not included.
|
int |
getDepth()
Get depth of the trie.
|
TrieNode<T> |
getNode(char[] word,
boolean exact)
Find a node that represents the given word.
|
TrieNode<T> |
getRoot()
Get the root node of the trie.
|
void |
insert(char[] word,
int startIndex,
int endIndex,
T data)
Insert a substring of word with payload data inside the trie.
|
String |
toString()
Get String representation of trie.
|
void |
updateOrInsertData(char[] word,
Function<T,T> updateFunction)
Insert or update data in the trie.
|
boolean |
walkPath(char[] word,
Consumer<TrieNode<T>> consumer,
boolean includePrefixMatch)
Walk the trie down along a path (up to the outermost node still matching
the word) and call the consumer function every time (from the root to the
outermost node).
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcontains, containsPrefix, delete, getData, insert, insert, insert, insert, insert, insert, insert, updateOrInsertDatapublic void clear()
PrefixDictionaryclear in interface PrefixDictionary<T extends Serializable>public void insert(char[] word,
int startIndex,
int endIndex,
T data)
PrefixDictionaryinsert in interface PrefixDictionary<T extends Serializable>word - word to be insertedstartIndex - index to begin the substring with (inclusive)endIndex - index to end the substring at (exclusive)data - payload datapublic void updateOrInsertData(char[] word,
Function<T,T> updateFunction)
PrefixDictionaryupdateOrInsertData in interface PrefixDictionary<T extends Serializable>word - word to searchupdateFunction - function that returns the inserted value (if input data is
null) or returns the updates value (if input data is present)public final boolean containsPrefix(char[] word)
PrefixDictionarycontainsPrefix in interface PrefixDictionary<T extends Serializable>word - word to search forpublic boolean contains(char[] word)
PrefixDictionarycontains in interface PrefixDictionary<T extends Serializable>word - word to search forpublic void delete(char[] word)
PrefixDictionarydelete in interface PrefixDictionary<T extends Serializable>word - word to search forpublic T getData(char[] word)
PrefixDictionarygetData in interface PrefixDictionary<T extends Serializable>word - word to searchpublic TrieNode<T> getNode(char[] word, boolean exact)
word - word to search forexact - flag if exact node search should be performedpublic boolean walkPath(char[] word,
Consumer<TrieNode<T>> consumer,
boolean includePrefixMatch)
word - word to walk uponconsumer - consumer function to call on every nodeincludePrefixMatch - if this flag is true, the last node is also included if the
word parameter is only a prefix of the path of this node (no
exact match)public int getDepth()
PrefixDictionarygetDepth in interface PrefixDictionary<T extends Serializable>Copyright © 2015 illucIT Software GmbH. All rights reserved.