private long computeMemorySizeInBytes(AbstractNode root) { if (root.getLevel() == 0) { return ABSTRACT_NODE_INSTANCE_SIZE + ENVELOPE_INSTANCE_SIZE + root.getChildBoundables().stream().mapToLong(child -> computeMemorySizeInBytes((ItemBoundable) child)).sum(); } return ABSTRACT_NODE_INSTANCE_SIZE + ENVELOPE_INSTANCE_SIZE + root.getChildBoundables().stream().mapToLong(child -> computeMemorySizeInBytes((AbstractNode) child)).sum(); }
private long computeMemorySizeInBytes(AbstractNode root) { if (root.getLevel() == 0) { return ABSTRACT_NODE_INSTANCE_SIZE + ENVELOPE_INSTANCE_SIZE + root.getChildBoundables().stream().mapToLong(child -> computeMemorySizeInBytes((ItemBoundable) child)).sum(); } return ABSTRACT_NODE_INSTANCE_SIZE + ENVELOPE_INSTANCE_SIZE + root.getChildBoundables().stream().mapToLong(child -> computeMemorySizeInBytes((AbstractNode) child)).sum(); }
private long computeMemorySizeInBytes(AbstractNode root) { if (root.getLevel() == 0) { return ABSTRACT_NODE_INSTANCE_SIZE + ENVELOPE_INSTANCE_SIZE + root.getChildBoundables().stream().mapToLong(child -> computeMemorySizeInBytes((ItemBoundable) child)).sum(); } return ABSTRACT_NODE_INSTANCE_SIZE + ENVELOPE_INSTANCE_SIZE + root.getChildBoundables().stream().mapToLong(child -> computeMemorySizeInBytes((AbstractNode) child)).sum(); }
/** * @param level -1 to get items */ private void boundablesAtLevel(int level, AbstractNode top, Collection boundables) { Assert.isTrue(level > -2); if (top.getLevel() == level) { boundables.add(top); return; } for (Iterator i = top.getChildBoundables().iterator(); i.hasNext(); ) { Boundable boundable = (Boundable) i.next(); if (boundable instanceof AbstractNode) { boundablesAtLevel(level, (AbstractNode)boundable, boundables); } else { Assert.isTrue(boundable instanceof ItemBoundable); if (level == -1) { boundables.add(boundable); } } } return; }
public static void printLevels(TestTree t, PrintStream out) { for (int i = 0; i <= t.getRoot().getLevel(); i++) { printBoundables(t.boundablesAtLevel(i), "Level " + i, out); } }
public void testEmptyTree() { TestTree t = new TestTree(2); t.build(); assertEquals(0, t.getRoot().getLevel()); assertEquals(1, t.boundablesAtLevel(0).size()); assertEquals(0, t.boundablesAtLevel(1).size()); assertEquals(0, t.boundablesAtLevel(-1).size()); assertEquals(0, t.query(0.5, 0.5).size()); } }
public void test() { TestTree t = new TestTree(2); t.insert(2, 6, "A"); t.insert(2, 4, "B"); t.insert(2, 3, "C"); t.insert(2, 4, "D"); t.insert(0, 1, "E"); t.insert(2, 4, "F"); t.insert(5, 6, "G"); t.build(); assertEquals(2, t.getRoot().getLevel()); assertEquals(4, t.boundablesAtLevel(0).size()); assertEquals(2, t.boundablesAtLevel(1).size()); assertEquals(1, t.boundablesAtLevel(2).size()); assertEquals(1, t.query(0.5, 0.5).size()); assertEquals(0, t.query(1.5, 1.5).size()); assertEquals(2, t.query(4.5, 5.5).size()); }