index.js
function sort(values, boxes, indices, left, right) {
    if (left >= right) return;

    const pivot = values[(left + right) >> 1];
    let i = left - 1;
    let j = right + 1;

    while (true) {
        do i++; while (values[i] < pivot);
        do j--; while (values[j] > pivot);
        if (i >= j) break;
        swap(values, boxes, indices, i, j);
    }

    sort(values, boxes, indices, left, j);
    sort(values, boxes, indices, j + 1, right);
}
function sort(values, boxes, indices, left, right) {
    if (left >= right) return;

    const pivot = values[(left + right) >> 1];
    let i = left - 1;
    let j = right + 1;

    while (true) {
        do i++; while (values[i] < pivot);
        do j--; while (values[j] > pivot);
        if (i >= j) break;
        swap(values, boxes, indices, i, j);
    }

    sort(values, boxes, indices, left, j);
    sort(values, boxes, indices, j + 1, right);
}
function sort ( values , boxes , indices , left , right ) { if ( left >= right ) return ; const pivot = values [ ( left + right ) >> 1 ] ; let i = left - 1 ; let j = right + 1 ; while ( true ) { do i ++ ; while ( values [ i ] < pivot ) ; do j -- ; while ( values [ j ] > pivot ) ; if ( i >= j ) break ; swap ( values , boxes , indices , i , j ) ; } sort ( values , boxes , indices , left , j ) ; sort ( values , boxes , indices , j + 1 , right ) ; }
custom quicksort that sorts bbox data alongside the hilbert values
custom quicksort that sorts bbox data alongside the hilbert values