Search in sources :

Example 1 with DoubleBigArray

use of com.facebook.presto.common.array.DoubleBigArray in project presto by prestodb.

the class Flatbush method buildTree.

private DoubleBigArray buildTree() {
    // We initialize it to NaN, because all comparisons with NaN are false.
    // Thus the normal intersection logic will not select uninitialized
    // nodes.
    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;
}
Also used : DoubleBigArray(com.facebook.presto.common.array.DoubleBigArray)

Aggregations

DoubleBigArray (com.facebook.presto.common.array.DoubleBigArray)1