Class Trie
java.lang.Object
|
+--Trie
- public class Trie
- extends java.lang.Object
Warning this class serves as both a Trie
and a Trie-node. These duties should probably be
broken into separate classes. The current version
suppots Joggle-lookup in addition to insertion/search
so it exposes Nodes to client code
Limitation: supports wors up to 1024 characters long
Implements a trie for storing strings/string prefixes
This trie stores only 26 characters per node, these
characters are assumed to be lowercase. For uppercase
or mixed case change the protected fields
- ALPH_SIZE which is the size of the alphabet
(defaults to 26)
- FIRST is the first of ALPH_SIZE consecutive
characters used in making the trie (defaults to 'a'
This trie supports adding Strings and C-style strings where a
C-style string is a '\0' terminated array of char
- See Also:
JoggleWordFinder
|
Field Summary |
protected static int |
ALPH_SIZE
|
protected static char |
FIRST
|
|
Constructor Summary |
Trie()
create a new emtpy Trie |
|
Method Summary |
void |
addCString(char[] s)
|
void |
addString(java.lang.String s)
Add a string to the trie, subsequent calls
of isWord(s) will return true |
protected int |
charToIndex(char ch)
|
Trie |
childAt(char ch)
|
java.util.List |
getWords()
return a List of every word in the Trie |
boolean |
isWord()
|
boolean |
isWord(java.lang.String s)
determine if a word is in the trie |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ALPH_SIZE
protected static int ALPH_SIZE
FIRST
protected static char FIRST
Trie
public Trie()
- create a new emtpy Trie
addString
public void addString(java.lang.String s)
- Add a string to the trie, subsequent calls
of isWord(s) will return true
- Parameters:
s - The string added to Trie
addCString
public void addCString(char[] s)
getWords
public java.util.List getWords()
- return a List of every word in the Trie
isWord
public boolean isWord(java.lang.String s)
- determine if a word is in the trie
- Parameters:
s - The string searched for- Returns:
- true iff s is in trie (rooted here)
isWord
public boolean isWord()
- Returns:
- true iff path from some root to this node is a word
childAt
public Trie childAt(char ch)
- Parameters:
ch - Character used to index node (find child)- Returns:
- Trie formed from this by indexing using ch
charToIndex
protected int charToIndex(char ch)