Source:
private DoubleBigArray buildTree() { DoubleBigArray tree = new DoubleBigArray(Double.NaN); tree.ensureCapacity(levelOffsets[levelOffsets.length - 1] + ENVELOPE_SIZE); sortByHilberIndex(this.items); int writeOffset = 0; int readOffset; for (T item : items) { tree.set(writeOffset++, item.getExtent().getXMin()); tree.set(writeOffset++, item.getExtent().getYMin()); tree.set(writeOffset++, item.getExtent().getXMax()); tree.set(writeOffset++, item.getExtent().getYMax()); } int numChildren = items.length; for (int childLevel = 0; childLevel < levelOffsets.length - 1; childLevel++) { readOffset = levelOffsets[childLevel]; writeOffset = levelOffsets[childLevel + 1]; int numParents = 0; double xMin = Double.POSITIVE_INFINITY; double yMin = Double.POSITIVE_INFINITY; double xMax = Double.NEGATIVE_INFINITY; double yMax = Double.NEGATIVE_INFINITY; for (int child = 0; child < numChildren; child++) { xMin = min(xMin, tree.get(readOffset++)); yMin = min(yMin, tree.get(readOffset++)); xMax = max(xMax, tree.get(readOffset++)); yMax = max(yMax, tree.get(readOffset++)); if (readOffset % (degree * ENVELOPE_SIZE) == 0) { numParents++; tree.set(writeOffset++, xMin); tree.set(writeOffset++, yMin); tree.set(writeOffset++, xMax); tree.set(writeOffset++, yMax); xMin = Double.POSITIVE_INFINITY; yMin = Double.POSITIVE_INFINITY; xMax = Double.NEGATIVE_INFINITY; yMax = Double.NEGATIVE_INFINITY; } } if (readOffset % (degree * ENVELOPE_SIZE) != 0) { numParents++; tree.set(writeOffset++, xMin); tree.set(writeOffset++, yMin); tree.set(writeOffset++, xMax); tree.set(writeOffset++, yMax); } numChildren = numParents; } return tree; }

Target:
private DoubleBigArray buildTree() { DoubleBigArray tree = new DoubleBigArray(Double.NaN); tree.ensureCapacity(levelOffsets[levelOffsets.length - 1] + ENVELOPE_SIZE); if (items.length > degree) { sortByHilbertIndex(items); } int writeOffset = 0; for (T item : items) { tree.set(writeOffset++, item.getExtent().getXMin()); tree.set(writeOffset++, item.getExtent().getYMin()); tree.set(writeOffset++, item.getExtent().getXMax()); tree.set(writeOffset++, item.getExtent().getYMax()); } int numChildren = items.length; for (int level = 0; level < levelOffsets.length - 1; level++) { int readOffset = levelOffsets[level]; writeOffset = levelOffsets[level + 1]; int numParents = 0; double xMin = Double.POSITIVE_INFINITY; double yMin = Double.POSITIVE_INFINITY; double xMax = Double.NEGATIVE_INFINITY; double yMax = Double.NEGATIVE_INFINITY; int child = 0; for (; child < numChildren; child++) { xMin = min(xMin, tree.get(readOffset++)); yMin = min(yMin, tree.get(readOffset++)); xMax = max(xMax, tree.get(readOffset++)); yMax = max(yMax, tree.get(readOffset++)); if ((child + 1) % degree == 0) { numParents++; tree.set(writeOffset++, xMin); tree.set(writeOffset++, yMin); tree.set(writeOffset++, xMax); tree.set(writeOffset++, yMax); xMin = Double.POSITIVE_INFINITY; yMin = Double.POSITIVE_INFINITY; xMax = Double.NEGATIVE_INFINITY; yMax = Double.NEGATIVE_INFINITY; } } if (child % degree != 0) { numParents++; tree.set(writeOffset++, xMin); tree.set(writeOffset++, yMin); tree.set(writeOffset++, xMax); tree.set(writeOffset++, yMax); } numChildren = numParents; } return tree; }