pub struct Settings { pub build_id: u64, /// Where one zoom's chunks go while they wait for the merge. See [`crate::tilespill`]. /// /// Beside the output archive, as `.tilechunks`, matching where the feature spill is placed. /// Truncated at the start of every zoom and removed at the end of each, so it holds one zoom. pub scratch: PathBuf, /// Force the tile-chunk spill through the scratch *file* even when the budget gate would pick /// anonymous pagefile-backed memory. Set from `MAPS_ANON_SPILL` (unset, or any value but /// `1`/`true`/`yes`, forces files): on a box whose commit headroom is tens of GB against a /// ~900 GB estimate, anon staging pages the merge to death -- files page too, but against /// the scratch volume rather than the commit limit that aborts the build. Same chunks, same /// offsets, same bytes; the merge reads through the same `ChunkReader` either way. pub force_chunk_spill_file: bool, /// The DEM heightmap dataset to sample one grid per output tile from. /// See [`crate::dem::Dem`]. A tile with no DEM under it carries no heightmap /// section (stays 16-byte). pub dem: crate::dem::Dem, /// Place-label id (tagged node) -> the tagged relation id of the admin boundary it names, from /// stage A. The tiler stamps each `places` label whose id is a key here with the linked id in /// the body's region-link table, so a tap on the label outlines that exact region. Empty when no /// links were found (the section is then omitted from every tile). pub region_links: std::collections::HashMap, /// Place-label id (tagged, `country` places only) -> the label's start zoom, from /// footprint × headcount (see `extract_fallback::country_zoom`). The tiler drops the /// label below its start zoom — same shape as `region_links`, probe-only so the /// archive stays deterministic. Absent ids keep the schema floor (z0): a missing /// score must never hide a country. pub country_zooms: std::collections::HashMap, } /// One chunk's share of a zoom, keyed on `(tile id, layer id)`. /// /// Keyed on the **tile id**, not on `(x, y)`. Those are different orders: `tile_id` walks a Hilbert /// curve, so row-major `(x, y)` ascends through it out of sequence and the writer rejects the /// archive. Cheap to get wrong and caught only by an ordering check, which is why the writer has /// one. /// /// Flat rather than `tile -> layer -> layer`. A nested map pays a whole inner `BTreeMap` node — /// eleven `BodyLayer` slots, most of a kilobyte — for every tile, and nearly every tile carries one /// or two layers; with a chunk map per chunk that overhead is multiplied by the chunk count. /// Flattening puts eleven *entries* in a node instead, and changes no order: `(tile, layer)` /// ascending is tile-major with layers in id order inside it, which is what the nested form yielded /// and what the writer needs. type Chunk = BTreeMap<(u64, u8), ChunkEntry>; /// One tile-layer in a chunk map: the geometry plus the label strings its features name. /// /// Names ride beside the layer (not inside `BodyLayer`, which is the codec's type) from `push` /// through the spill and the merge to encode, where per-layer tables fuse into the body's one. /// A chunk entry's `names` is deduplicated in first-use order, so `name_idx == i` names /// `names[i - 1]` — the same convention as the body's table, which is what makes the merge's /// remap a pure index translation. /// /// `ids` rides the same way and is simpler: it holds values rather than indices, so a merge /// concatenates it instead of remapping it. It is empty for every layer but `places` and `poi`, /// and dense-parallel to `layer.features` for those two — `ids[i]` is the OSM element that /// produced `features[i]`. #[derive(Debug, Clone, PartialEq)] pub struct ChunkEntry { pub layer: BodyLayer, pub names: Vec, pub ids: Vec, /// The per-feature turn-lane masks, dense-parallel to `layer.features` on the `roads` layer and /// empty on every other. Rides the merge the way `ids` does — concatenated, not remapped — and /// is remapped alongside `ids` when `coalesce` and stage C rebuild the feature vector. pub turn_lanes: Vec, /// The per-feature S3DB attributes, dense-parallel to `layer.features` on the `buildings` layer /// and empty on every other. Rides the merge like `ids` (concatenated, not remapped) and is /// remapped alongside it when `coalesce` and stage C rebuild the feature vector, so the body's /// building side table stays aligned to the features it describes. pub buildings: Vec, /// The per-feature directional carriageway split, dense-parallel to `layer.features` on the /// `roads` layer and empty on every other. Rides the merge like `ids` (concatenated, not /// remapped) and is remapped alongside it when `coalesce` rebuilds the feature vector. Stage C /// is not given it: a road is a line, and `rings::normalise` never drops one. pub carriageways: Vec, } impl ChunkEntry { pub(crate) fn new(layer_id: u8) -> ChunkEntry { ChunkEntry { layer: BodyLayer::new(layer_id), names: Vec::new(), ids: Vec::new(), turn_lanes: Vec::new(), buildings: Vec::new(), carriageways: Vec::new(), } } } /// Intern `name` into a first-use-ordered table, returning its 1-based body index. fn intern_name(names: &mut Vec, name: Option<&str>) -> u16 { match name.filter(|n| !n.is_empty()) { None => tilecodec::mamaps::body::NAME_NONE, Some(name) => match names.iter().position(|n| n == name) { Some(at) => at as u16 + 1, None => { let idx = names.len() as u16 + 1; names.push(name.to_string()); idx } }, } } /// What one chunk contributed to a zoom's counters. Only ever summed, so the order they are summed /// in cannot change the answer. #[derive(Debug, Default, Clone, Copy)] struct Tally { features: u64, points: u64, dropped: u64, // TEMP-PROFILE: per-stage map walls, summed across chunks (durations // add; order irrelevant). Removed with the probes. NOT Copy (Duration // is, but the explicit add below keeps the accounting visible). profile: TallyProfile, } /// TEMP-PROFILE: per-stage map-phase walls carried in the tally. Removed /// with the probes. #[derive(Debug, Default, Clone, Copy)] struct TallyProfile { project: std::time::Duration, annotate: std::time::Duration, filter: std::time::Duration, subdiv: std::time::Duration, } impl Tally { fn add(&mut self, other: Tally) { self.features += other.features; self.points += other.points; self.dropped += other.dropped; self.profile.project += other.profile.project; self.profile.annotate += other.profile.annotate; self.profile.filter += other.profile.filter; self.profile.subdiv += other.profile.subdiv; } /// TEMP-PROFILE: attach this chunk's stage walls. Removed with the probes. fn profile_add( &mut self, project: std::time::Duration, annotate: std::time::Duration, filter: std::time::Duration, subdiv: std::time::Duration, ) { self.profile.project += project; self.profile.annotate += annotate; self.profile.filter += filter; self.profile.subdiv += subdiv; } }