use of org.trie4j.NodeVisitor in project trie4j by takawitter.
the class PatriciaTrieWikipediaTest method afterVerification.
@Override
protected void afterVerification(Trie trie) throws Exception {
final AtomicInteger nodes = new AtomicInteger();
final AtomicInteger leaves = new AtomicInteger();
Algorithms.traverseByDepth(trie.getRoot(), new NodeVisitor() {
@Override
public boolean visit(Node node, int nest) {
if (node.isTerminate())
leaves.incrementAndGet();
else
nodes.incrementAndGet();
return true;
}
});
System.out.println(String.format("%d nodes and %d leaves", nodes.intValue(), leaves.intValue()));
super.afterVerification(trie);
}
use of org.trie4j.NodeVisitor in project trie4j by takawitter.
the class BitVectorExp method main.
public static void main(String[] args) throws Exception {
Trie trie = new PatriciaTrie();
int c = 0;
// You can download archive from http://dumps.wikimedia.org/jawiki/latest/
LapTimer t = new LapTimer();
for (String word : new WikipediaTitles()) {
trie.insert(word);
c++;
if (c == maxCount)
break;
}
t.lapMillis("trie building done. %d words.", c);
final BytesSuccinctBitVector bv = new BytesSuccinctBitVector(5000000);
final AtomicInteger nodeCount = new AtomicInteger();
Algorithms.traverseByDepth(trie.getRoot(), new NodeVisitor() {
@Override
public boolean visit(Node node, int nest) {
Node[] children = node.getChildren();
if (children != null) {
int n = node.getChildren().length;
for (int i = 0; i < n; i++) {
bv.append(true);
}
}
bv.append(false);
nodeCount.incrementAndGet();
return true;
}
});
trie = null;
t.lapMillis("done. %d nodes inserted. do rank and select", nodeCount.intValue());
for (int i = 0; i < c; i += 100) {
int count = bv.rank(i, true);
bv.select(count, true);
}
t.lapMillis("done.");
Thread.sleep(10000);
}
use of org.trie4j.NodeVisitor in project trie4j by takawitter.
the class MapTailPatriciaTrieWithConcatTailBuilderWikipediaTest method afterVerification.
@Override
protected void afterVerification(Trie trie) throws Exception {
final AtomicInteger nodes = new AtomicInteger();
final AtomicInteger leaves = new AtomicInteger();
Algorithms.traverseByDepth(trie.getRoot(), new NodeVisitor() {
@Override
public boolean visit(Node node, int nest) {
if (node.isTerminate())
leaves.incrementAndGet();
else
nodes.incrementAndGet();
return true;
}
});
System.out.println(String.format("%d nodes and %d leaves", nodes.intValue(), leaves.intValue()));
super.afterVerification(trie);
}
Aggregations