Interface PrefixTrie
- All Known Subinterfaces:
SuffixTrie
- All Known Implementing Classes:
PrefixTrieImpl
,ReversePrefixTrie
public interface PrefixTrie
The PrefixTrie can perform fast prefix matching. By traversing the trie based on the characters in
the prefix being searched, it is possible to find all strings in the Trie that have the given prefix.
-
Method Summary
Modifier and TypeMethodDescriptionint
The number of complete words in this trie.boolean
Checks if a word exists in this trie.boolean
Deletes a word from the trie.boolean
Inserts a word into the trie.boolean
Checks if prefix is present in this trie.A detailed string representation of the structure of this trie.int
size()
The number of nodes in this trie.startsWith
(String prefix, int limit) Try to find strings which start with prefix.
-
Method Details
-
startsWith
Try to find strings which start with prefix. Matching strings are always in lexicographical order.- Parameters:
prefix
- to look forlimit
- maximum number of found strings- Returns:
- collection of words with the same prefix
-
contains
Checks if a word exists in this trie.- Parameters:
string
- to check- Returns:
- true if word is in this trie
-
isPrefix
Checks if prefix is present in this trie.- Parameters:
prefix
- to check- Returns:
- true if prefix exists
-
insert
Inserts a word into the trie. Duplicate words will be ignored.- Parameters:
string
- word to be inserted- Returns:
- true if the word was inserted false if it already existed
-
delete
Deletes 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.- Parameters:
string
- to be deleted- Returns:
- true if word is successfully deleted false if word was not in the trie
-
size
int size()The number of nodes in this trie.- Returns:
- number of nodes
-
completeWords
int completeWords()The number of complete words in this trie.- Returns:
- number of complete words
-
prettyString
String prettyString()A detailed string representation of the structure of this trie.- Returns:
- detailed string
-