Search in sources :

Example 1 with BSTIteratorAll

use of ch.ethz.globis.phtree.v16.bst.BSTIteratorAll in project phtree by tzaeschke.

the class PhTree16 method toStringTree.

private void toStringTree(StringBuilderLn sb, int currentDepth, Node node, long[] prefix, boolean printValue) {
    String ind = "*";
    for (int i = 0; i < currentDepth; i++) {
        ind += "-";
    }
    sb.append(ind + "il=" + node.getInfixLen() + " pl=" + (node.getPostLen()) + " ec=" + node.getEntryCount() + " inf=[");
    // for a leaf node, the existence of a sub just indicates that the value exists.
    if (node.getInfixLen() > 0) {
        long mask = (-1L) << node.getInfixLen();
        mask = ~mask;
        mask <<= node.getPostLen() + 1;
        for (int i = 0; i < dims; i++) {
            sb.append(Bits.toBinary(prefix[i] & mask) + ",");
        }
    }
    currentDepth += node.getInfixLen();
    sb.appendLn("]  " + node);
    // To clean previous postfixes.
    BSTIteratorAll iter = node.iterator();
    while (iter.hasNextEntry()) {
        BSTEntry o = iter.nextEntry();
        if (o.getValue() instanceof Node) {
            sb.appendLn(ind + "# " + o.getKey() + "  +");
            toStringTree(sb, currentDepth + 1, (Node) o.getValue(), o.getKdKey(), printValue);
        } else {
            // post-fix
            sb.append(ind + Bits.toBinary(o.getKdKey(), DEPTH_64));
            sb.append("  hcPos=" + o.getKey());
            if (printValue) {
                sb.append("  v=" + o.getValue());
            }
            sb.appendLn("");
        }
    }
}
Also used : BSTIteratorAll(ch.ethz.globis.phtree.v16.bst.BSTIteratorAll) BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry)

Example 2 with BSTIteratorAll

use of ch.ethz.globis.phtree.v16.bst.BSTIteratorAll in project phtree by tzaeschke.

the class TestBST16 method checkEmpty.

private void checkEmpty(Node ht) {
    assertEquals(0, ht.getEntryCount());
    BSTEntry e = ht.bstGet(12345);
    assertNull(e);
    // iterate
    BSTIteratorAll iter = ht.iterator();
    assertFalse(iter.hasNextEntry());
    BSTIteratorMask iterMask = new BSTIteratorMask().reset(ht.getRoot(), 0, 0xFFFFFFFFFFFEL, ht.getEntryCount());
    assertFalse(iterMask.hasNextEntry());
    BSTEntry e2 = ht.bstRemove(12345, null, null, tree);
    assertNull(e2);
}
Also used : BSTIteratorMask(ch.ethz.globis.phtree.v16.bst.BSTIteratorMask) BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry) BSTIteratorAll(ch.ethz.globis.phtree.v16.bst.BSTIteratorAll)

Example 3 with BSTIteratorAll

use of ch.ethz.globis.phtree.v16.bst.BSTIteratorAll in project phtree by tzaeschke.

the class TestBST16 method runTest.

private void runTest(List<BSTEntry> list, String prefix) {
    Node ht = create();
    // populate
    long l11 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        // if (i%1000 == 0)
        // System.out.println("ins=" + i);
        // ht.bstPut((Integer)i.getValue(), i);
        BSTEntry newBE = ht.bstGetOrCreate((int) i.getValue(), tree);
        newBE.set((int) i.getValue(), i.getKdKey(), i.getValue());
        // Check
        BSTEntry be = ht.bstGet((Integer) i.getValue());
        assertEquals((int) i.getValue(), (int) be.getValue());
    }
    long l12 = System.currentTimeMillis();
    assertEquals(list.size(), ht.getEntryCount());
    // println(ht.getStats().toString());
    // lookup
    long l21 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        BSTEntry e = ht.bstGet((Integer) i.getValue());
        // assertNotNull("i=" + i, e);
        int x = (int) e.getValue();
        assertEquals(i.getValue(), x);
    }
    long l22 = System.currentTimeMillis();
    // iterate
    long l51 = System.currentTimeMillis();
    BSTIteratorAll iter = ht.iterator();
    long prev = -1;
    while (iter.hasNextEntry()) {
        long current = iter.nextEntry().getKey();
        assertEquals(prev + 1, current);
        prev = current;
    }
    assertEquals(prev, list.size() - 1);
    long l52 = System.currentTimeMillis();
    long l61 = System.currentTimeMillis();
    BSTIteratorMask iterMask = new BSTIteratorMask().reset(ht.getRoot(), 0, 0xFFFFFFFFFFFEL, ht.getEntryCount());
    prev = -2;
    while (iterMask.hasNextEntry()) {
        long current = iterMask.nextEntry().getKey();
        assertEquals(prev + 2, current);
        prev = current;
    }
    assertEquals(prev, list.size() - 2);
    long l62 = System.currentTimeMillis();
    // replace some
    long l31 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        // ht.bstPut((Integer)i.getValue(), new BSTEntry(i.getKdKey(), -(Integer)i.getValue()));
        BSTEntry newBE = ht.bstGetOrCreate((Integer) i.getValue(), tree);
        newBE.setValue(-(Integer) i.getValue());
    }
    long l32 = System.currentTimeMillis();
    assertEquals(list.size(), ht.getEntryCount());
    // remove some
    long l41 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        assertEquals(-(Integer) i.getValue(), ht.bstRemove((Integer) i.getValue(), i.getKdKey(), null, tree).getValue());
    }
    long l42 = System.currentTimeMillis();
    assertEquals(0, ht.getEntryCount());
    println(prefix + "Load: " + (l12 - l11));
    println(prefix + "Get:  " + (l22 - l21));
    println(prefix + "Iter: " + (l52 - l51));
    println(prefix + "IterM:" + (l62 - l61));
    println(prefix + "Load: " + (l32 - l31));
    println(prefix + "Rem : " + (l42 - l41));
    println();
}
Also used : BSTIteratorMask(ch.ethz.globis.phtree.v16.bst.BSTIteratorMask) BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry) BSTIteratorAll(ch.ethz.globis.phtree.v16.bst.BSTIteratorAll) Node(ch.ethz.globis.phtree.v16.Node)

Example 4 with BSTIteratorAll

use of ch.ethz.globis.phtree.v16.bst.BSTIteratorAll in project phtree by tzaeschke.

the class PhTree16 method toStringPlain.

private void toStringPlain(StringBuilderLn sb, Node node) {
    BSTIteratorAll iter = node.iterator();
    while (iter.hasNextEntry()) {
        BSTEntry o = iter.nextEntry();
        // inner node?
        if (o.getValue() instanceof Node) {
            toStringPlain(sb, (Node) o.getValue());
        } else {
            sb.append(Bits.toBinary(o.getKdKey(), DEPTH_64));
            sb.appendLn("  v=" + o.getValue());
        }
    }
}
Also used : BSTIteratorAll(ch.ethz.globis.phtree.v16.bst.BSTIteratorAll) BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry)

Example 5 with BSTIteratorAll

use of ch.ethz.globis.phtree.v16.bst.BSTIteratorAll in project phtree by tzaeschke.

the class TestBST16compute method runTest.

private void runTest(List<BSTEntry> list, String prefix) {
    Node ht = create();
    // populate
    long l11 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        // if (i%1000 == 0)
        // System.out.println("ins=" + i);
        // ht.bstPut((Integer)i.getValue(), i);
        ht.bstCompute((int) i.getValue(), i.getKdKey(), tree, true, (longs, o) -> {
            assertSame(i.getKdKey(), longs);
            assertNull(o);
            // TODO clone 'i'?
            return i.getValue();
        });
        // Check
        BSTEntry be = ht.bstGet((Integer) i.getValue());
        assertEquals((int) i.getValue(), (int) be.getValue());
    }
    long l12 = System.currentTimeMillis();
    assertEquals(list.size(), ht.getEntryCount());
    println(ht.getStats().toString());
    // lookup
    long l21 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        BSTEntry e = ht.bstGet((Integer) i.getValue());
        // assertNotNull("i=" + i, e);
        int x = (int) e.getValue();
        assertEquals(i.getValue(), x);
    }
    long l22 = System.currentTimeMillis();
    // iterate
    long l51 = System.currentTimeMillis();
    BSTIteratorAll iter = ht.iterator();
    long prev = -1;
    while (iter.hasNextEntry()) {
        long current = iter.nextEntry().getKey();
        assertEquals(prev + 1, current);
        prev = current;
    }
    assertEquals(prev, list.size() - 1);
    long l52 = System.currentTimeMillis();
    long l61 = System.currentTimeMillis();
    BSTIteratorMask iterMask = new BSTIteratorMask().reset(ht.getRoot(), 0, 0xFFFFFFFFFFFEL, ht.getEntryCount());
    prev = -2;
    while (iterMask.hasNextEntry()) {
        long current = iterMask.nextEntry().getKey();
        assertEquals(prev + 2, current);
        prev = current;
    }
    assertEquals(prev, ((list.size() - 1) & 0xFFFFFFFE));
    long l62 = System.currentTimeMillis();
    // replace some
    long l31 = System.currentTimeMillis();
    for (BSTEntry i : list) {
        // ht.bstPut((Integer)i.getValue(), new BSTEntry(i.getKdKey(), -(Integer)i.getValue()));
        ht.bstCompute((Integer) i.getValue(), i.getKdKey(), tree, true, (longs, o) -> -(Integer) i.getValue());
    }
    long l32 = System.currentTimeMillis();
    assertEquals(list.size(), ht.getEntryCount());
    // remove some
    long l41 = System.currentTimeMillis();
    boolean[] found = new boolean[1];
    for (BSTEntry i : list) {
        found[0] = false;
        ht.bstCompute((Integer) i.getValue(), i.getKdKey(), tree, true, (longs, o) -> {
            found[0] = true;
            return null;
        });
        assertTrue(found[0]);
    }
    long l42 = System.currentTimeMillis();
    assertEquals(0, ht.getEntryCount());
    println(prefix + "Load: " + (l12 - l11));
    println(prefix + "Get:  " + (l22 - l21));
    println(prefix + "Iter: " + (l52 - l51));
    println(prefix + "IterM:" + (l62 - l61));
    println(prefix + "Load: " + (l32 - l31));
    println(prefix + "Rem : " + (l42 - l41));
    println();
}
Also used : BSTIteratorMask(ch.ethz.globis.phtree.v16.bst.BSTIteratorMask) BSTEntry(ch.ethz.globis.phtree.v16.Node.BSTEntry) BSTIteratorAll(ch.ethz.globis.phtree.v16.bst.BSTIteratorAll) Node(ch.ethz.globis.phtree.v16.Node)

Aggregations

BSTIteratorAll (ch.ethz.globis.phtree.v16.bst.BSTIteratorAll)7 BSTEntry (ch.ethz.globis.phtree.v16.Node.BSTEntry)6 BSTIteratorMask (ch.ethz.globis.phtree.v16.bst.BSTIteratorMask)4 Node (ch.ethz.globis.phtree.v16.Node)2