public class TernaryTreeDictionary extends Object implements Dictionary
Modifier and Type | Field and Description |
---|---|
protected TernaryTree |
tree
Ternary tree used for searching.
|
Constructor and Description |
---|
TernaryTreeDictionary(TernaryTree tt)
Creates a dictionary that uses the supplied ternary tree for dictionary searches.
|
TernaryTreeDictionary(WordList wordList)
Creates a new balanced tree dictionary from the supplied
WordList . |
TernaryTreeDictionary(WordList wordList,
boolean useMedian)
Creates a new dictionary instance from the given
WordList . |
Modifier and Type | Method and Description |
---|---|
TernaryTree |
getTernaryTree()
Returns the underlying ternary tree used by this dictionary.
|
static void |
main(String[] args)
Provides command line access to a ternary tree dictionary.
|
String[] |
nearSearch(String word,
int distance)
Returns an array of strings which are near to the supplied word by the supplied distance.
|
String[] |
partialSearch(String word)
Returns an array of strings which partially match the supplied word.
|
boolean |
search(String word)
Returns whether the supplied word exists in the dictionary.
|
long |
size()
Returns the number of words in this dictionary
|
protected final TernaryTree tree
public TernaryTreeDictionary(WordList wordList)
WordList
. This constructor creates a balanced tree
by inserting from the median of the word list, which may require additional work depending on the WordList
implementation.
NOTE While using an unsorted word list produces correct results, it may dramatically reduce search efficiency. Using a sorted word list is recommended.
wordList
- list of words used to back the dictionary. This list is used exclusively to initialize the
internal TernaryTree
used by the dictionary, and may be safely discarded after dictionary
creation.public TernaryTreeDictionary(WordList wordList, boolean useMedian)
WordList
.wordList
- list of words used to back the dictionary. This list is used exclusively to initialize the
internal TernaryTree
used by the dictionary, and may be safely discarded after dictionary
creation.
NOTE While using an unsorted word list produces correct results, it may dramatically reduce search efficiency. Using a sorted word list is recommended.
useMedian
- set to true to force creation of a balanced tree by inserting into the tree from the median of
the WordList
outward. Depending on the word list implementation, this may require
additional work to access the median element on each insert.public TernaryTreeDictionary(TernaryTree tt)
tt
- ternary tree used to back dictionary.public long size()
Dictionary
size
in interface Dictionary
public boolean search(String word)
Dictionary
search
in interface Dictionary
word
- to search forpublic String[] partialSearch(String word)
TernaryTree.partialSearch(java.lang.String)
.word
- to search forpublic String[] nearSearch(String word, int distance)
TernaryTree.nearSearch(java.lang.String, int)
.word
- to search fordistance
- for valid matchpublic TernaryTree getTernaryTree()
Copyright © 2003-2024 Virginia Tech. All Rights Reserved.