good stuff

This commit is contained in:
Andras Schmelczer 2026-03-15 21:10:54 +00:00
parent ea8389ef40
commit f4de0eeb9f
39 changed files with 5165 additions and 348 deletions

View file

@ -1,4 +1,5 @@
use axum::http::StatusCode;
use rustc_hash::FxHashMap;
use tracing::warn;
use crate::consts::{H3_PRECOMPUTE_MAX, H3_REQUEST_MAX, H3_REQUEST_MIN};
@ -45,6 +46,28 @@ pub fn cell_for_row(
)
}
/// Like cell_for_row but caches parent lookups in the provided map.
#[inline]
pub fn cell_for_row_cached(
row: usize,
precomputed: &[u64],
h3_res: h3o::Resolution,
need_parent: bool,
cache: &mut FxHashMap<u64, u64>,
) -> u64 {
let max_cell = precomputed[row];
if !need_parent || max_cell == 0 {
return max_cell;
}
*cache.entry(max_cell).or_insert_with(|| {
let cell = h3o::CellIndex::try_from(max_cell).expect("precomputed H3 cell must be valid");
u64::from(
cell.parent(h3_res)
.expect("parent resolution must be valid"),
)
})
}
/// Whether the given resolution requires computing a parent from precomputed cells.
#[inline]
pub fn needs_parent(resolution: u8) -> bool {