use of org.trie4j.Trie 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.Trie in project trie4j by takawitter.
the class Issue_031 method test_UnsafeDoubleArray.
@Test
public void test_UnsafeDoubleArray() throws Throwable {
Trie trie = new PatriciaTrie();
insertLines(trie, FILE_NAME);
@SuppressWarnings("deprecation") Trie da = new org.trie4j.doublearray.UnsafeDoubleArray(trie);
Assert.assertFalse(trie.contains("you"));
Assert.assertFalse(da.contains("you"));
}
use of org.trie4j.Trie in project trie4j by takawitter.
the class LOUDSTrieTest method test_save_load.
@Test
public void test_save_load() throws Exception {
String[] words = { "こんにちは", "さようなら", "おはよう", "おおきなかぶ", "おおやまざき" };
Trie lt = trieWithWords(words);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
try {
oos.writeObject(lt);
} finally {
oos.flush();
}
lt = (Trie) new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray())).readObject();
for (String w : words) {
Assert.assertTrue(lt.contains(w));
}
Assert.assertFalse(lt.contains("おやすみなさい"));
StringBuilder b = new StringBuilder();
Node[] children = lt.getRoot().getChildren();
for (Node n : children) {
char[] letters = n.getLetters();
b.append(letters[0]);
}
Assert.assertEquals("おこさ", b.toString());
}
use of org.trie4j.Trie in project trie4j by takawitter.
the class LOUDSTrieTest method test.
@Test
public void test() throws Exception {
String[] words = { "こんにちは", "さようなら", "おはよう", "おおきなかぶ", "おおやまざき" };
Trie lt = trieWithWords(words);
for (String w : words) {
Assert.assertTrue(w, lt.contains(w));
}
Assert.assertFalse(lt.contains("おやすみなさい"));
StringBuilder b = new StringBuilder();
Node[] children = lt.getRoot().getChildren();
for (Node n : children) {
char[] letters = n.getLetters();
b.append(letters[0]);
}
Assert.assertEquals("おこさ", b.toString());
}
use of org.trie4j.Trie in project trie4j by takawitter.
the class LongsConstantTimeSelect0TailLOUDSPPTrieWithSuffixTrieDenseTailArrayWikipediaSerializeTest method secondTrie.
@Override
protected Trie secondTrie(Trie firstTrie) {
Trie t = new TailLOUDSTrie(firstTrie, new LOUDSPPBvTree(new LongsRank0OnlySuccinctBitVector(), new LongsConstantTimeSelect0SuccinctBitVector()), new SuffixTrieDenseTailArrayBuilder());
t.trimToSize();
return t;
}
Aggregations