Search in sources :

Example 1 with FastTailCharIterator

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;
}
Also used : FastTailCharIterator(org.trie4j.tail.FastTailCharIterator)

Example 2 with FastTailCharIterator

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();
}
Also used : FastTailCharIterator(org.trie4j.tail.FastTailCharIterator)

Aggregations

FastTailCharIterator (org.trie4j.tail.FastTailCharIterator)2