/** * Override to collapse root DAG's that are one single bucket to the first DAG that has more * than one bucket */ @Override public DAG buildRoot() { if (ENABLE_EXPAND_COLLAPSE) { final long size = root.getTotalChildCount(); collapse(root); final long resultSize = root.getTotalChildCount(); checkState(size == resultSize, "expected size of %s, but got %s after collapse()", size, resultSize); } return root; }
/** * Override to collapse root DAG's that are one single bucket to the first DAG that has more * than one bucket */ @Override public DAG buildRoot() { if (ENABLE_EXPAND_COLLAPSE) { final long size = root.getTotalChildCount(); collapse(root); final long resultSize = root.getTotalChildCount(); checkState(size == resultSize, "expected size of %s, but got %s after collapse()", size, resultSize); } return root; }
public void collapse(final DAG dag) { if (dag.getState() != STATE.CHANGED) { return; } final int numBuckets = dag.numBuckets(); if (numBuckets == 0) { return; } final List<TreeId> bucketIds = dag.bucketList(); if (numBuckets == 1) { final TreeId replaceId = bucketIds.get(0); DAG child = getOrCreateDAG(replaceId); setParent(child, dag); // for (TreeId childId : dag.bucketList()) { // child = getOrCreateDAG(childId); // collapse(dag, child); // } } else { for (TreeId bucketId : bucketIds) { DAG child = getOrCreateDAG(bucketId); collapse(child); } } }
public void collapse(final DAG dag) { if (dag.getState() != STATE.CHANGED) { return; } final int numBuckets = dag.numBuckets(); if (numBuckets == 0) { return; } final List<TreeId> bucketIds = dag.bucketList(); if (numBuckets == 1) { final TreeId replaceId = bucketIds.get(0); DAG child = getOrCreateDAG(replaceId); setParent(child, dag); // for (TreeId childId : dag.bucketList()) { // child = getOrCreateDAG(childId); // collapse(dag, child); // } } else { for (TreeId bucketId : bucketIds) { DAG child = getOrCreateDAG(bucketId); collapse(child); } } }
/** * Tests {@code deepPath} collapses to {@code collapsedPath} when calling {@code buildRoot()}, * but doesn't change {@code strategy}, uses a cloned strategy instead */ private void assertCollapsesTo(QuadTreeClusteringStrategy strategy, String deepPath, String collapsedPath, Iterable<Node> expectedNodes) { QuadTreeClusteringStrategy clone = support.clone(strategy); support.assertDag(clone, deepPath, expectedNodes); clone.collapse(clone.root); support.assertDag(clone, collapsedPath, expectedNodes); }
/** * Tests {@code deepPath} collapses to {@code collapsedPath} when calling {@code buildRoot()}, * but doesn't change {@code strategy}, uses a cloned strategy instead */ private void assertCollapsesTo(QuadTreeClusteringStrategy strategy, String deepPath, String collapsedPath, Iterable<Node> expectedNodes) { QuadTreeClusteringStrategy clone = support.clone(strategy); support.assertDag(clone, deepPath, expectedNodes); clone.collapse(clone.root); support.assertDag(clone, collapsedPath, expectedNodes); }
public @Test void testCollapseRootUnpromotables() { // unpromotable at root because it overlaps the 4 quadrants final Envelope unpromotableBounds = new Envelope(-1, 1, -1, 1); QuadTreeClusteringStrategy strategy = support.newStrategy(); for (int i = 0; i < 130; i++) { Node node = support.createNode(String.valueOf(i), unpromotableBounds); strategy.put(node); } assertEquals(130, strategy.root.getTotalChildCount()); assertEquals(1, strategy.root.numBuckets()); assertEquals(2, strategy.depth(strategy.root)); DAG unpromotables = support.findDAG(strategy, "[4]"); assertEquals(12, unpromotables.numBuckets()); assertNotNull(unpromotables); strategy.collapse(strategy.root); assertEquals(1, strategy.depth(strategy.root)); assertEquals(130, strategy.root.getTotalChildCount()); assertEquals(12, strategy.root.numBuckets()); }
public @Test void testCollapseRootUnpromotables() { // unpromotable at root because it overlaps the 4 quadrants final Envelope unpromotableBounds = new Envelope(-1, 1, -1, 1); QuadTreeClusteringStrategy strategy = support.newStrategy(); for (int i = 0; i < 130; i++) { Node node = support.createNode(String.valueOf(i), unpromotableBounds); strategy.put(node); } assertEquals(130, strategy.root.getTotalChildCount()); assertEquals(1, strategy.root.numBuckets()); assertEquals(2, strategy.depth(strategy.root)); DAG unpromotables = support.findDAG(strategy, "[4]"); assertEquals(12, unpromotables.numBuckets()); assertNotNull(unpromotables); strategy.collapse(strategy.root); assertEquals(1, strategy.depth(strategy.root)); assertEquals(130, strategy.root.getTotalChildCount()); assertEquals(12, strategy.root.numBuckets()); }