Skip to main content

cover_ranges

Function cover_ranges 

Source
pub fn cover_ranges(
    xmin: f64,
    xmax: f64,
    ymin: f64,
    ymax: f64,
    bits: u8,
    max_ranges: usize,
) -> Vec<(u64, u64)>
Expand description

Decompose a query bbox into Hilbert key RANGES at one level: a quadtree refinement over Hilbert quadrants, emitting one [lo, hi] run for every square fully inside the box, dropping squares fully outside, and splitting the ones that straddle the box’s edge. max_ranges caps the output; the refinement spends that budget where it buys the most.

The budget is spent WASTE-FIRST. Every straddling square carries the number of its cells that lie outside the box; the square with the most outside cells is always the next one split, because that split removes the most cells the scan would otherwise read and throw away. When one more split could push the count of runs past the budget, every square still straddling is emitted whole – a slightly larger scan, filtered exactly per posting, never a miss. A depth-first descent that checked its budget against its own stack was the earlier shape of this: three pending siblings per level ate fifty of sixty-four slots at sixteen bits, so it stopped refining at the fourth level and read five times the box for a 50 km radius.