/// The ways-only pass: one [`Seg`] per consecutive resolvable ref pair. /// /// Re-reading the way blobs replaces a cache of every routable way and every one /// of its refs — 32 GB at planet scale — with the cost of inflating the way /// blobs a second time. Ways are a small minority of a planet file's blobs and /// `blob_kinds` lets the pass skip the rest outright, so the trade is heavily in /// favour of re-reading. /// One Morton-key piece: its slot range plus its disjoint slice of the key array. type KeyPiece<'a> = ((usize, usize), &'a mut [(u64, u32)]); #[derive(Default)] struct WayPass { segs: Vec, lanes: Vec, names: LocalNames, } #[derive(Default)] struct Pass2 { /// `(dense id, lat_e7, lon_e7)`, scattered index-aligned in the sink. locs: Vec<(u32, i32, i32)>, /// `(dense id, stop code)`, as owned bytes. Interning is deferred until every /// way name is in the pool, because a name's offset is its position in the /// pool: interning a stop code early would shift every way name after it and /// rewrite the whole of `road_names.bin`. stops: Vec<(u32, Vec)>, /// Slots this chunk claimed (first sight of the id) in the parallel scan. claimed: u64, } #[derive(Clone, Copy)] struct TmpEdge { source: u32, target: u32, dist_mm: u32, name_offset: u32, type_: u8, speed_limit: u8, lane_off: u32, lane_count: u16, /// Chain this edge traverses, or [`NO_CHAIN`]. Only used to make the write /// order total; the geometry comes from the point range below. chain: u32, /// True when it runs from the chain's last point to its first, so the stored /// polyline has to be read backwards. chain_rev: bool, /// The chain's polyline in `chains.pts`. Carried here rather than looked up per /// edge: the header file is 24 GB at planet scale, so seeking back into it once /// per edge would be a billion cold random reads. pts_start: u64, pts_len: u32, } /// Build-time choices that change the shape of the build rather than its output /// contract. #[derive(Clone, Default)] pub struct Options { /// Restrict chains to a single OSM way, which trades some collapsing for the /// segment array and its incidence index. See [`crate::chains`]. pub within_way_chains: bool, /// How many source-partitioned rounds to write the pack in. One round is the /// whole graph at once; more rounds trade extra sequential passes over the /// chain spill for a proportionally smaller edge buffer. Zero means one. pub rounds: u32, /// Where to put the chain spill. Defaults to the output directory. /// /// Worth separating because `chains.pts` is the only file the build reads /// randomly — once per edge that stores a polyline — so it wants a disk whose /// seeks are cheap, while the output only ever needs sequential writes and can /// go wherever there is room. Putting the spill on a slow mount cost more wall /// clock on California than every other stage put together. pub spill_dir: Option, /// Where to put `chains.pts` specifically, if it should not sit beside /// `chains.hdr`. /// /// The header is the larger file — about 24 GB against 18 GB at planet scale — /// but it is only ever streamed from the front, so it can live somewhere roomy /// and slow while the randomly-read points go somewhere fast and small. pub spill_pts_dir: Option, /// Print the [`Census`] report after the build. Changes no output file. pub stats: bool, /// Cap on the parallel pool. `None` leaves it to [`crate::par::threads`]. pub threads: Option, /// A `.mdem` heightmap dataset (`dem_ingest`) to bake a per-node elevation from. /// /// `None` omits `elevation.bin` entirely — the graph is still valid and the device reads every /// node's elevation as 0 (WS-G's route profile simply comes out flat). When set, every graph /// node is sampled from the DEM and its metres written to `elevation.bin`; a node off the DEM's /// coverage bakes as 0. pub dem: Option, /// Region bbox filter: keep only ways with at least one node inside. /// /// `None` (world) keeps everything. `Some` (california) drops every routable /// way whose nodes all fall outside — the graph then covers only the region, /// which is what makes a california build fast and small. Stop nodes are /// filtered the same way: a stop outside the region never enters the graph. pub bbox: Option, } impl Options { fn round_count(&self) -> u32 { self.rounds.max(1) } } pub fn build(input: &Path, out_dir: &Path) -> Result { build_with(input, out_dir, Options::default()) } include!("graph_build_part1_s1.rs"); include!("graph_build_part1_s2.rs");