Class ReversePrefixTrie
java.lang.Object
com.abstractkamen.datastructures.impl.trees.search.PrefixTrieImpl
com.abstractkamen.datastructures.impl.trees.search.ReversePrefixTrie
- All Implemented Interfaces:
PrefixTrie,SuffixTrie
This implementation uses the same insert/delete/search algorithm as the
PrefixTrieImpl. In order to implement the
SuffixTrie it reverses the input string. The cost of insert/delete/search is double that of the PrefixTrieImpl, but is
still O(m) where m is the length of the input string.-
Nested Class Summary
Nested classes/interfaces inherited from class com.abstractkamen.datastructures.impl.trees.search.PrefixTrieImpl
PrefixTrieImpl.PrefixTrieNode -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanDeletes a word from the trie.Try to find strings which end with suffix.booleanInserts a word into the trie.booleanChecks if prefix is present in this trie.booleanChecks if suffix is present in this trie.protected booleanPrefixTrieImpl.completeWordsdecrementing condition.startsWith(String prefix, int limit) Try to find strings which start with prefix.toString()protected voidvisitWordNode(PrefixTrieImpl.PrefixTrieNode node, StringBuilder visitor, StringBuilder currentChars) Visit a node which we know is a word.Methods inherited from class com.abstractkamen.datastructures.impl.trees.search.PrefixTrieImpl
completeWords, contains, delete, getRoot, insert, prettyString, search, sizeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface com.abstractkamen.datastructures.api.trees.search.PrefixTrie
completeWords, contains, prettyString, size
-
Constructor Details
-
ReversePrefixTrie
public ReversePrefixTrie()
-
-
Method Details
-
shouldDecrementWordOnDelete
Description copied from class:PrefixTrieImplPrefixTrieImpl.completeWordsdecrementing condition. Can be overridden in extensions.- Overrides:
shouldDecrementWordOnDeletein classPrefixTrieImpl- Parameters:
n- word node- Returns:
- true if
PrefixTrieImpl.completeWordsshould be decremented
-
visitWordNode
protected void visitWordNode(PrefixTrieImpl.PrefixTrieNode node, StringBuilder visitor, StringBuilder currentChars) Description copied from class:PrefixTrieImplVisit a node which we know is a word.- Overrides:
visitWordNodein classPrefixTrieImpl- Parameters:
node- word nodevisitor- sb visitorcurrentChars- word so far
-
insert
Description copied from interface:PrefixTrieInserts a word into the trie. Duplicate words will be ignored.- Specified by:
insertin interfacePrefixTrie- Overrides:
insertin classPrefixTrieImpl- Parameters:
string- word to be inserted- Returns:
- true if the word was inserted false if it already existed
-
delete
Description copied from interface:PrefixTrieDeletes a word from the trie. The number of complete words will be decremented by one and the size of the trie will shrink by the number of unique characters and their placements in the deleted word if they aren't used by a different word.- Specified by:
deletein interfacePrefixTrie- Overrides:
deletein classPrefixTrieImpl- Parameters:
string- to be deleted- Returns:
- true if word is successfully deleted false if word was not in the trie
-
endsWith
Description copied from interface:SuffixTrieTry to find strings which end with suffix. Matching strings are always in arbitrary order.- Specified by:
endsWithin interfaceSuffixTrie- Parameters:
suffix- to look forlimit- maximum number of found strings- Returns:
- collection of words with the same suffix
-
isSuffix
Description copied from interface:SuffixTrieChecks if suffix is present in this trie.- Specified by:
isSuffixin interfaceSuffixTrie- Parameters:
suffix- to check- Returns:
- true if suffix exists
-
isPrefix
Description copied from interface:PrefixTrieChecks if prefix is present in this trie.- Specified by:
isPrefixin interfacePrefixTrie- Overrides:
isPrefixin classPrefixTrieImpl- Parameters:
prefix- to check- Returns:
- true if prefix exists
-
startsWith
Description copied from interface:PrefixTrieTry to find strings which start with prefix. Matching strings are always in lexicographical order.- Specified by:
startsWithin interfacePrefixTrie- Overrides:
startsWithin classPrefixTrieImpl- Parameters:
prefix- to look forlimit- maximum number of found strings- Returns:
- collection of words with the same prefix
-
toString
- Overrides:
toStringin classPrefixTrieImpl
-