public Node putNode(QuadTreeClusteringStrategy quad, Quadrant... location) { Preconditions.checkNotNull(location); long fnumb = quad.root == null ? 0 : quad.root.getTotalChildCount(); String quadInfo = Arrays.toString(location); Node n = createNode("node # " + fnumb + ", at " + quadInfo, location); quad.put(n); return n; }
public Node putNode(QuadTreeClusteringStrategy quad, Quadrant... location) { Preconditions.checkNotNull(location); long fnumb = quad.root == null ? 0 : quad.root.getTotalChildCount(); String quadInfo = Arrays.toString(location); Node n = createNode("node # " + fnumb + ", at " + quadInfo, location); quad.put(n); return n; }
/** * Overrides to implement a simple optimization for the case where the node bounds haven't * changed and hence avoid calling remove and then put, but call put only, since the * {@code NodeId} is guaranteed to lay on the same bucket at any depth. */ @Override public int update(Node oldNode, Node newNode) { Optional<Envelope> oldBounds = oldNode.bounds(); Optional<Envelope> newBounds = newNode.bounds(); if (oldBounds.equals(newBounds)) { // in case the bounds didn't change, put will override the old value, // otherwise need to remove old and add new separately Preconditions.checkArgument(oldNode.getName().equals(newNode.getName())); int delta = put(newNode); if (delta == 0 && !oldNode.equals(newNode)) { delta = 1; } } return super.update(oldNode, newNode); }
/** * Overrides to implement a simple optimization for the case where the node bounds haven't * changed and hence avoid calling remove and then put, but call put only, since the * {@code NodeId} is guaranteed to lay on the same bucket at any depth. */ @Override public int update(Node oldNode, Node newNode) { Optional<Envelope> oldBounds = oldNode.bounds(); Optional<Envelope> newBounds = newNode.bounds(); if (oldBounds.equals(newBounds)) { // in case the bounds didn't change, put will override the old value, // otherwise need to remove old and add new separately Preconditions.checkArgument(oldNode.getName().equals(newNode.getName())); int delta = put(newNode); if (delta == 0 && !oldNode.equals(newNode)) { delta = 1; } } return super.update(oldNode, newNode); }
@Test public void testInitOriginalSinglePointFeature() { QuadTreeClusteringStrategy orig = support.newStrategy(); Node node = support.createNode("1", new Envelope(1, 1, 1, 1)); orig.put(node); RevTree quadTree = DAGTreeBuilder.build(orig, support.store()); assertEquals(1, quadTree.size()); QuadTreeClusteringStrategy update = support.newStrategy(quadTree); Node node2 = support.createNode("2", new Envelope(2, 2, 2, 2)); update.remove(node); update.put(node2); RevTree quadTree2 = DAGTreeBuilder.build(update, support.store()); assertEquals(1, quadTree2.size()); List<Node> lnodes = findNode("2", quadTree2, support.store()); assertEquals(1, lnodes.size()); assertEquals(node2, lnodes.get(0)); }
@Test public void testInitOriginalSinglePointFeature() { QuadTreeClusteringStrategy orig = support.newStrategy(); Node node = support.createNode("1", new Envelope(1, 1, 1, 1)); orig.put(node); RevTree quadTree = DAGTreeBuilder.build(orig, support.store()); assertEquals(1, quadTree.size()); QuadTreeClusteringStrategy update = support.newStrategy(quadTree); Node node2 = support.createNode("2", new Envelope(2, 2, 2, 2)); update.remove(node); update.put(node2); RevTree quadTree2 = DAGTreeBuilder.build(update, support.store()); assertEquals(1, quadTree2.size()); List<Node> lnodes = findNode("2", quadTree2, support.store()); assertEquals(1, lnodes.size()); assertEquals(node2, lnodes.get(0)); }
newNodes.forEach((n) -> assertEquals(1, updateBuilder.put(n)));
newNodes.forEach((n) -> assertEquals(1, updateBuilder.put(n)));
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()); }
Envelope bounds = new Envelope(i, i, 1, 1); Node node = support.createNode("node # " + i, bounds); orig.put(node);
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()); }
Envelope bounds = new Envelope(i, i, 1, 1); Node node = support.createNode("node # " + i, bounds); orig.put(node);
Envelope bounds = new Envelope(i, i, 1, 1); Node node = support.createNode("node # " + i, bounds); orig.put(node);
Envelope bounds = new Envelope(i, i, 1, 1); Node node = support.createNode("node # " + i, bounds); orig.put(node);