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
impl GeoCellHistogram
Sourcepub fn observe_posting(&mut self, cell_id: u64)
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).
Sourcepub fn merge(&mut self, other: &Self)
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.
Sourcepub fn total_bucket_mass(&self) -> u64
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.
Sourcepub fn capped_for_wire(
&self,
max_fine_bytes: usize,
max_remainder_bytes: usize,
) -> Self
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.
Sourcepub fn capped_coarse_map(&self, max_coarse_bytes: usize) -> BTreeMap<u64, u32>
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.
Sourcepub fn wire_bytes(&self) -> usize
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).
Sourcepub fn estimate_ranges(&self, ranges: &[(u32, u32)]) -> u64
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).
Sourcepub fn estimate_ranges_breakdown(
&self,
ranges: &[(u32, u32)],
) -> EstimateRangesBreakdown
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.
Sourcepub fn encode_body(&self, out: &mut Vec<u8>)
pub fn encode_body(&self, out: &mut Vec<u8>)
Serialize as a self-versioned section (an appendable trailer of the
profile blob, like TickHistogram).
Sourcepub fn decode_body(buf: &mut &[u8]) -> Result<Self, StatsError>
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
impl Clone for GeoCellHistogram
Source§fn clone(&self) -> GeoCellHistogram
fn clone(&self) -> GeoCellHistogram
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more