/// The reference path: build every segment, then collapse chains across way /// boundaries with [`compact`]. /// /// Kept as the baseline the within-way path is measured against. Its cost is the /// segment array and the incidence CSR over it, which together are the reason a /// planet build does not fit. #[allow(clippy::too_many_arguments)] fn collapse_segments( input: &Path, spill_dir: &Path, spill_pts_dir: &Path, blobs: &[pbf::BlobLoc], blob_kinds: &[u8], index: &NodeIndex, coords: &[geom::Pt], stop: &Bitset, slots: u32, filter: RegionFilter, pool: &mut NamePool, timer: &mut crate::timing::PhaseTimer, ) -> Result { timer.switch("collapse-segments"); // One record per consecutive way-node pair, still carrying both directions' // lane data. Splitting into directed edges is deferred until after // compaction, because pairing a `u -> v` edge with its `v -> u` twin is only // unambiguous while they are still one object. let mut segs: Vec = Vec::new(); let mut lane_pool: Vec = Vec::new(); let way_kinds = pbf::run_pass_sink( input, blobs, pbf::PassSpec { blob_kinds: Some(blob_kinds), want: KIND_WAYS, label: "Pass 3: segments" }, WayPass::default, |state, block| way_blob(state, block, index, coords, filter), |chunk| { let name_map = chunk.names.flush(pool).map_err(io_err)?; let lane_base = lane_pool.len() as u32; lane_pool.extend_from_slice(&chunk.lanes); cap_lane_pool(lane_pool.len())?; segs.reserve(chunk.segs.len()); for mut s in chunk.segs { s.name_offset = if s.name_offset == u32::MAX { NO_NAME } else { name_map[s.name_offset as usize] }; if s.fwd_lane_count > 0 { s.fwd_lane_off += lane_base; } if s.bwd_lane_count > 0 { s.bwd_lane_off += lane_base; } segs.push(s); } Ok(()) }, )?; report_way_blobs(blobs.len(), &way_kinds); let raw_edge_count: u64 = segs.iter().map(|s| if s.oneway { 1u64 } else { 2 }).sum(); println!( "Built {} segment(s) ({raw_edge_count} directed edge(s) before compaction)", segs.len() ); timer.switch("collapse-compact"); let comp = compact::compact(slots, &segs, &lane_pool, |n| coords[n as usize], |n| { stop.get(u64::from(n)) }); drop(segs); // A slot with no coordinates has no segments either, so compaction has no // reason to collapse it and would hand it a real node id. Filter it out here // instead: this is the second half of the dangling-reference guard. let mut kept = Bitset::new(u64::from(slots)); for i in 0..slots { if comp.new_id[i as usize] != REMOVED && index.present.get(u64::from(i)) { kept.set(u64::from(i)); } } let spill = chains::Spill::split(spill_dir, spill_pts_dir); spill.write(&comp.chains, &comp.pts, coords)?; Ok(Collapsed { spill, kept, lane_pool, chain_count: comp.chains.len() as u64, splits: comp.splits, raw_edge_count, }) }