|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object FixedArrayTrie
An implementation of tries with linked lists. Each node of the trie is a
fixed-size array of pointers on its sons. All algorithms (addToTrie,
isInTrie, removeFromTrie) are linear. The space used is bounded
by Card(alphabet)*sum of lengths of words
.
Field Summary | |
static Alphabet |
alphabet
The alphabet used to form the strings composing the trie. |
FixedArrayTrie[] |
next
The array of sons of the node. |
boolean |
terminal
True if the node is terminal. |
Constructor Summary | |
FixedArrayTrie()
|
Method Summary | |
void |
addToTrie(java.lang.String s)
Adds the word s to the trie. |
void |
fromFile(java.lang.String name)
Builds a trie representing the list of strings read from a file line by line. |
boolean |
isInTrie(java.lang.String s)
Returns true if the trie contains s .
|
boolean |
isLeaf()
Returns true if the node p is a leaf of the trie.
|
Pair |
longestPrefixInTrie(java.lang.String s,
int j)
Computes the pair composed of the length of the longest prefix of s[j..n-1] in the trie and the vertex reached by this prefix. |
static void |
main(java.lang.String[] args)
|
void |
removeFromTrie(java.lang.String s)
Removes the string s from the trie. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public static Alphabet alphabet
public boolean terminal
public FixedArrayTrie[] next
Constructor Detail |
public FixedArrayTrie()
Method Detail |
public Pair longestPrefixInTrie(java.lang.String s, int j)
LongestPrefixInTrie()
of Section 1.3.1.
Complexity: linear in the length of s
.
longestPrefixInTrie
in interface Trie
s
- the input stringj
- the starting index
public boolean isInTrie(java.lang.String s)
s
.
Implements the function IsInTrie()
of Section 1.3.1.
Complexity: linear in the length of s
.
isInTrie
in interface Trie
public void addToTrie(java.lang.String s)
AddToTrie()
of Section 1.3.1.
Complexity: linear in the length
of s
.
addToTrie
in interface Trie
s
- the string to be addedpublic boolean isLeaf()
p
is a leaf of the trie.
Implements the function IsLeaf()
of Section 1.3.1.
isLeaf
in interface Trie
public void removeFromTrie(java.lang.String s)
RemoveFromTrie()
of Section 1.3.1.
Complexity: linear in the length of s
.
removeFromTrie
in interface Trie
s
- the string to be removedpublic java.lang.String toString()
public void fromFile(java.lang.String name) throws java.io.IOException
fromFile
in interface Trie
name
- the name of the file
java.io.IOException
public static void main(java.lang.String[] args) throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |