public void recycleGraph( KdTree tree ) { if( tree.root != null ) { // step through the graph and recycle each node open.add(tree.root); while (!open.isEmpty()) { KdTree.Node n = open.remove(open.size() - 1); if (n.left != null) open.add(n.left); if (n.right != null) open.add(n.right); recycle(n); } tree.root = null; } unusedTrees.add(tree); }
public void recycleGraph( KdTree tree ) { if( tree.root != null ) { // step through the graph and recycle each node open.add(tree.root); while (!open.isEmpty()) { KdTree.Node n = open.remove(open.size() - 1); if (n.left != null) open.add(n.left); if (n.right != null) open.add(n.right); recycle(n); } tree.root = null; } unusedTrees.add(tree); }
@Test public void recycle() { KdTreeMemory alg = new KdTreeMemory(); KdTree.Node n = new KdTree.Node(); n.point = new double[2]; n.left = n; n.right = n; alg.recycle(n); assertTrue(n.point == null); assertTrue(n.left == null); assertTrue(n.right == null); assertEquals(1,alg.unusedNodes.size()); } @Test