use of org.trie4j.tail.FastTailCharIterator in project trie4j by takawitter.
the class TailPatriciaTrie method getNode.
public TailPatriciaTrieNode getNode(String text) {
TailPatriciaTrieNode node = root;
FastTailCharIterator it = new FastTailCharIterator(tails, -1);
int n = text.length();
for (int i = 0; i < n; i++) {
node = node.getChild(text.charAt(i));
if (node == null)
return null;
int ti = node.getTailIndex();
if (ti == -1)
continue;
it.setIndex(node.getTailIndex());
char c;
while ((c = it.getNext()) != '\0') {
i++;
if (i == n)
return null;
if (text.charAt(i) != c)
return null;
}
}
return node;
}
use of org.trie4j.tail.FastTailCharIterator in project trie4j by takawitter.
the class TailPatriciaTrie method contains.
@Override
public boolean contains(String text) {
TailPatriciaTrieNode node = root;
FastTailCharIterator it = new FastTailCharIterator(tails, -1);
int n = text.length();
for (int i = 0; i < n; i++) {
node = node.getChild(text.charAt(i));
if (node == null)
return false;
int ti = node.getTailIndex();
if (ti == -1)
continue;
it.setIndex(node.getTailIndex());
char c;
while ((c = it.getNext()) != '\0') {
i++;
if (i == n)
return false;
if (text.charAt(i) != c)
return false;
}
}
return node.isTerminate();
}
Aggregations