Skip to main content

GeoCellHistogram

Struct GeoCellHistogram 

Source
pub struct GeoCellHistogram {
    pub fine: BTreeMap<u32, u32>,
    pub coarse: BTreeMap<u64, u32>,
    pub remainder: BTreeMap<u32, RemainderBucket>,
}
Expand description

Sparse level-11 cell-count histogram (see the module docs).

Maps are BTreeMaps so the estimate can sum a query range without enumerating it: a coarse query cell’s descendants are contiguous in the dense index (one S2 cell never spans a face), so range sums cost O(log n + hits), never O(width).

The fine/coarse split exists because “counting” means different work at different posting levels. A posting whose cell is at level 9–10 expands: its cell contains 4–16 L11 buckets, so observation writes a +1 into each — the geometry’s footprint is flattened into per-bucket counts at collection time, bounded at 16 increments (the reason the floor is level 9; level 8 was moved onto the coarse side 2026-10 — its 64-bucket expansion multiplied a small posting population into half the fine map’s wire mass on real corpora, see the module docs). A posting below the floor would demand up to 4^(11 − level) increments — a face-level posting covers every L11 cell on one face, ≈ 4.2M — so instead of flattening it, observation stores ONE coarse entry keyed by the cell id at its NATIVE level, and the estimate defers the geometry→bucket mapping to plan time: each coarse entry contributes its count once when its L11 span (recomputed from the id by waratah_storage::geo_l11_bucket_range) intersects any query range. One huge geometry is one candidate, not thousands.

Fields§

§fine: BTreeMap<u32, u32>

Level-11 dense bucket index → Put posting count (saturating u32).

Receives every posting at level ≥ GEO_HISTOGRAM_COARSE_FLOOR_LEVEL via expansion. All keys are the SAME level, which is what makes the fixed dense u32 encoding (face ‖ 22 Hilbert bits) unambiguous: bucket index N means the same cell to every producer and consumer.

§coarse: BTreeMap<u64, u32>

Native u64 cell id → count for postings coarser than the fine floor (levels 0–8, the floor being count-once INCLUSIVE since the 2026-10 move; entries are never expanded — see the struct docs).

Keys stay at their NATIVE level deliberately: coarse keys span MIXED levels (unlike the uniform fine grid), so a compressed u32 would have to carry the level alongside the face/digits to stay unambiguous — a codec every touch point (collector, overlay, merge, wire, estimate) would need, while the native u64 id carries its own level intrinsically (the sentinel’s bit position IS the level) and plugs straight into geo_l11_bucket_range / geo_cell_level. The 4-byte saving per entry buys nothing at this map’s size: entries exist only for genuinely huge geometries, so the map is empty on regional data and a handful of entries at global scale.

§remainder: BTreeMap<u32, RemainderBucket>

Dropped-mass summary per level-8 parent (wire trim only; empty while the map is untrimmed).

Implementations§

Source§

impl GeoCellHistogram

Source

pub fn observe_posting(&mut self, cell_id: u64)

Observe one geo posting row (Put-only by contract — the collector and the apply-path overlay both filter on the op before calling this).

Level ≥ 9 postings expand into their (≤ 16) L11 descendant buckets (level 8 and below ride the coarse map — see the struct docs); malformed cell ids are ignored (the collector ignores undecodable rows the same way).

Source

pub fn merge(&mut self, other: &Self)

Algebraic merge: per-key saturating adds on all three maps. Order independent — saturating add is min(a + b, u32::MAX), and min is associative, so shard roll-ups are order independent.

Source

pub fn is_empty(&self) -> bool

Whether no posting was ever observed (merge identity).

Source

pub fn total_bucket_mass(&self) -> u64

Summed bucket incidences (fine + coarse values, before any trim). NOT the posting count: a coarse-floor posting expanded into N L11 buckets contributes N here. Debug/telemetry value only — the estimator never reads it.

Source

pub fn capped_for_wire( &self, max_fine_bytes: usize, max_remainder_bytes: usize, ) -> Self

Wire-trimmed copy: coarse entries pass through untouched here (their frame has its own trim, Self::capped_coarse_map), then fine entries largest-count-first (bucket index ascending tie-break, deterministic) while the fine side fits max_fine_bytes. Dropped fine mass is summarized per L8 parent into remainder; the remainder then obeys the same rank-and-keep discipline under max_remainder_bytes — largest-total parents first, and beyond the budget the smallest-mass parents are dropped and read EMPTY (bounded under-estimate, advisory path only).

An input that already carries a remainder (a re-trim at the rollup boundary, or a merged profile of trimmed shards) passes it through: this round’s drops merge INTO it, they never replace it — otherwise a second trim would silently discard the first round’s summarized mass.

Call only at transport boundaries; SST blobs and shard merges stay full-fidelity.

Source

pub fn capped_coarse_map(&self, max_coarse_bytes: usize) -> BTreeMap<u64, u32>

The coarse map trimmed for its own transport frame: rank-and-keep under max_coarse_bytes — count descending, native cell id ascending tie-break, deterministic — the same discipline the fine map and remainder obey.

The down-bias caveat (the one deliberately under-biased trim in the stats package): unlike dropped fine mass, a dropped coarse entry has NO summary to fall back on — it reads EMPTY in every window touching its span, so over-budget coarse maps under-estimate candidate counts, the UNSAFE direction for broadcast-vs-shuffle. Every other trim in this package degrades through a summary (the remainder) or biases up; this one is accepted because the coarse population is postings of genuinely huge geometries (few entries per corpus) and the budget is set with headroom over the census-measured population. If a corpus ever saturates this budget, the fix is a coarse-side summary (the remainder’s twin), not a bigger frame — re-derive the trade-off rather than trimming deeper.

Idempotent and merge-stable: re-trimming a kept subset under the same budget keeps it; a merged pair of trimmed maps re-trims to the top-K of the union.

Source

pub fn wire_bytes(&self) -> usize

Wire size of this histogram’s serialization (what the transport budget accounting charges for the section; matches encode_body).

Source

pub fn estimate_ranges(&self, ranges: &[(u32, u32)]) -> u64

Estimated Put postings for a query covering given as disjoint inclusive level-11 dense-index ranges (see waratah_geo::covering::covering_l11_ranges).

Ladder, per range: present fine buckets read exact counts; absent runs read their L8 parent’s average when the parent carries remainder mass (zero when it does not — empty space estimates empty, including a parent dropped by the remainder’s own wire budget); coarse entries intersecting any range add their count once each. Clamped to ≥ 1 for a non-empty covering — estimates order plans, never prune (§10).

Source

pub fn estimate_ranges_breakdown( &self, ranges: &[(u32, u32)], ) -> EstimateRangesBreakdown

Per-rung accounting of one Self::estimate_ranges call — the census --window decomposition. estimate_ranges delegates here, so the ladder logic has one home.

Source

pub fn encode_body(&self, out: &mut Vec<u8>)

Serialize as a self-versioned section (an appendable trailer of the profile blob, like TickHistogram).

Source

pub fn decode_body(buf: &mut &[u8]) -> Result<Self, StatsError>

Decode a section produced by Self::encode_body; consumes exactly its own bytes (trailing input belongs to the caller).

Trait Implementations§

Source§

impl Clone for GeoCellHistogram

Source§

fn clone(&self) -> GeoCellHistogram

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GeoCellHistogram

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for GeoCellHistogram

Source§

fn default() -> GeoCellHistogram

Returns the “default value” for a type. Read more
Source§

impl PartialEq for GeoCellHistogram

Source§

fn eq(&self, other: &GeoCellHistogram) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for GeoCellHistogram

Source§

impl StructuralPartialEq for GeoCellHistogram

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,