try {
BTree btree = new BTree(pool, (byte) 0, false, pool.getCacheManager(), file, 0.1);
btree.create((short) -1);
for (int i = 1; i <= COUNT; i++) {
Value value = new PrefixValue(99, new DoubleValue(i));
btree.addValue(value, i);
}
for (int i = 1; i <= COUNT; i++) {
Value value = new PrefixValue(100, new DoubleValue(i));
btree.addValue(value, i);
}
btree.flush();
System.out.println("BTree size: " + file.length());
for (int i = 1; i <= COUNT; i++) {
long p = btree.findValue(new PrefixValue(99, new DoubleValue(i)));
assertEquals(p, i);
}
Value prefix = new PrefixValue(99);
System.out.println("Testing IndexQuery.TRUNC_RIGHT");
IndexQuery query = new IndexQuery(IndexQuery.TRUNC_RIGHT, new PrefixValue(99));
btree.query(query, new PrefixIndexCallback());
assertEquals(COUNT, count);
System.out.println("Testing IndexQuery.GT");
for (int i = 0; i < COUNT; i += 10) {
query = new IndexQuery(IndexQuery.GT, new PrefixValue(99, new DoubleValue(i)));
btree.query(query, prefix, new PrefixIndexCallback());
assertEquals(COUNT - i, count);
}
System.out.println("Testing IndexQuery.GEQ");
query = new IndexQuery(IndexQuery.GEQ, new PrefixValue(99, new DoubleValue(COUNT / 2)));
btree.query(query, prefix, new PrefixIndexCallback());
assertEquals(COUNT / 2 + 1, count);
System.out.println("Testing IndexQuery.LT");
query = new IndexQuery(IndexQuery.LT, new PrefixValue(99, new DoubleValue(COUNT / 2)));
btree.query(query, prefix, new PrefixIndexCallback());
assertEquals(COUNT / 2 - 1, count);
System.out.println("Testing IndexQuery.LEQ");
query = new IndexQuery(IndexQuery.LEQ, new PrefixValue(99, new DoubleValue(COUNT / 2)));
btree.query(query, prefix, new PrefixIndexCallback());
assertEquals(COUNT / 2, count);
System.out.println("Testing IndexQuery.NEQ");
for (int i = 1; i <= COUNT / 8; i++) {
count = 0;
query = new IndexQuery(IndexQuery.NEQ, new PrefixValue(99, new DoubleValue(i)));
btree.query(query, prefix, new PrefixIndexCallback());
assertEquals(COUNT - 1, count);
}
btree.close();