offlinerouter: fix clippy warnings
- Commit
6b00468746312ba18148945772ef15d73ce335d9- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-17 14:09 UTC (18 days ago)
- Parents
dadaeaa
Drop unused imports and the duplicate dead SNAP_M constant, gate the test-only uses_blocked_sections hook behind cfg(test), and remove the unused raw-v7 test helper. Add Default impls for RadixHeap and RoutingScratchpad, type aliases for the ZSEC block cache keys, Range::contains and iterator forms for indexed loops, repeat_n, rfind, and regroup the route_diff hex literal; preserve the NaN guard in resample via an explicit is_nan check. Verified: cargo check -p offlinerouter --all-targets and cargo clippy -p offlinerouter --all-targets report no crate warnings; cargo test -p offlinerouter passes.
Diff
maps/src/main/rust/examples/route_diff.rs
diff --git a/maps/src/main/rust/examples/route_diff.rs b/maps/src/main/rust/examples/route_diff.rsindex cd1284b43c..e85d650d86 100644--- a/maps/src/main/rust/examples/route_diff.rs+++ b/maps/src/main/rust/examples/route_diff.rs@@ -740,9 +740,9 @@ fn bench(args: &[String]) -> Result<bool, String> { p.checksum = p .checksum .rotate_left(7)- .wrapping_add(u64::from(s.dist_mm))- .wrapping_mul(0x1000_0000_1B3)- ^ u64::from(s.time_10ms);+ .wrapping_add(s.dist_mm)+ .wrapping_mul(0x0100_0000_01B3)+ ^ s.time_10ms; } } }
maps/src/main/rust/src/corridor_geom.rs
diff --git a/maps/src/main/rust/src/corridor_geom.rs b/maps/src/main/rust/src/corridor_geom.rsindex e8f5e82f66..d79dc3345b 100644--- a/maps/src/main/rust/src/corridor_geom.rs+++ b/maps/src/main/rust/src/corridor_geom.rs@@ -51,7 +51,7 @@ pub fn distance_m(a: (i32, i32), b: (i32, i32)) -> f64 { /// The first and last points are always kept, so the walk covers the whole /// polyline and a short one still yields both ends. pub fn resample(points: &[(i32, i32)], step_m: f64) -> Vec<(i32, i32)> {- if points.len() < 2 || !(step_m > 0.0) {+ if points.len() < 2 || step_m.is_nan() || step_m <= 0.0 { return points.to_vec(); } let lerp = |a: i32, b: i32, t: f64| (f64::from(a) + (f64::from(b) - f64::from(a)) * t).round() as i32;
maps/src/main/rust/src/corridor_group.rs
diff --git a/maps/src/main/rust/src/corridor_group.rs b/maps/src/main/rust/src/corridor_group.rsindex 5b0345b57c..a36a0dd07c 100644--- a/maps/src/main/rust/src/corridor_group.rs+++ b/maps/src/main/rust/src/corridor_group.rs@@ -17,10 +17,6 @@ use std::collections::BTreeMap; /// tracks closer than this are one corridor. pub const CORRIDOR_M: f64 = 30.0; -/// How close a member's own survey has to come to the reference before it-/// stops drawing its own track and hands over to the corridor's.-const SNAP_M: f64 = 8.0;- /// Spacing of the probe samples along a polyline. pub const SAMPLE_M: f64 = 10.0;
maps/src/main/rust/src/corridor_spans.rs
diff --git a/maps/src/main/rust/src/corridor_spans.rs b/maps/src/main/rust/src/corridor_spans.rsindex e20e854510..d8e6822871 100644--- a/maps/src/main/rust/src/corridor_spans.rs+++ b/maps/src/main/rust/src/corridor_spans.rs@@ -8,7 +8,7 @@ //! Single-threaded like the grouping port: the tool spreads candidates //! across cores, but a viewport fetch holds dozens of routes. -use super::corridor_geom::{cumulative, point_at, slice_between};+use super::corridor_geom::{point_at, slice_between}; use super::corridor_group::{Corridor, Run}; use std::collections::{BTreeMap, HashMap};
maps/src/main/rust/src/graph_overlay.rs
diff --git a/maps/src/main/rust/src/graph_overlay.rs b/maps/src/main/rust/src/graph_overlay.rsindex a4250ad797..6f368b88da 100644--- a/maps/src/main/rust/src/graph_overlay.rs+++ b/maps/src/main/rust/src/graph_overlay.rs@@ -258,9 +258,9 @@ mod overlay_tests { } let mut edges_bytes = write_blocked(&edge_recs, 7); pad8(&mut edges_bytes);- edges_bytes.extend(std::iter::repeat(0u8).take(((e.div_ceil(ESCAPE_BLOCK) + 1) * 4) as usize));+ edges_bytes.extend(std::iter::repeat_n(0u8, ((e.div_ceil(ESCAPE_BLOCK) + 1) * 4) as usize)); pad8(&mut edges_bytes);- edges_bytes.extend(std::iter::repeat(0u8).take(EdgeBitmap::bytes(e) as usize));+ edges_bytes.extend(std::iter::repeat_n(0u8, EdgeBitmap::bytes(e) as usize)); let intermediate = vec![0u8; (EdgeBitmap::bytes(e) + 18) as usize]; let mut meta = Vec::new(); meta.extend_from_slice(&GRAPH_MAGIC.to_le_bytes());
maps/src/main/rust/src/graph_part2b.rs
diff --git a/maps/src/main/rust/src/graph_part2b.rs b/maps/src/main/rust/src/graph_part2b.rsindex 4042e05781..3ad44a1b17 100644--- a/maps/src/main/rust/src/graph_part2b.rs+++ b/maps/src/main/rust/src/graph_part2b.rs@@ -3,6 +3,7 @@ impl Graph { /// Whether this graph reads record tables through v7 blocked sections. /// Test hook: the loaders set the views, the accessors branch on them.+ #[cfg(test)] pub(crate) fn uses_blocked_sections(&self) -> bool { self.nodes_view.is_some() || self.edges_view.is_some() }
maps/src/main/rust/src/graph_part3.rs
diff --git a/maps/src/main/rust/src/graph_part3.rs b/maps/src/main/rust/src/graph_part3.rsindex c8d762ed38..21eefbeef6 100644--- a/maps/src/main/rust/src/graph_part3.rs+++ b/maps/src/main/rust/src/graph_part3.rs@@ -293,7 +293,7 @@ impl Graph { let mut qlat = (lat as i64).div_euclid(10) + i64::from((lat as i64).rem_euclid(10) >= 5); let mut qlon = (lon as i64).div_euclid(10) + i64::from((lon as i64).rem_euclid(10) >= 5); let mut at = 0usize;- let mut uvar = |at: &mut usize| -> Option<u64> {+ let uvar = |at: &mut usize| -> Option<u64> { let (mut r, mut s) = (0u64, 0u32); while *at < blob.len() { let b = blob[*at];
maps/src/main/rust/src/graph_part5.rs
diff --git a/maps/src/main/rust/src/graph_part5.rs b/maps/src/main/rust/src/graph_part5.rsindex b8249e81bb..d7d5be4832 100644--- a/maps/src/main/rust/src/graph_part5.rs+++ b/maps/src/main/rust/src/graph_part5.rs@@ -8,7 +8,7 @@ mod archive_tests { use super::*; use tilecodec::mamaps::archive::{- ARCHIVE_ALIGN, ArchiveEntry, ArchiveFooter, GRAPH_MAGIC, GRAPH_VERSION,+ ARCHIVE_ALIGN, ArchiveEntry, ArchiveFooter, GRAPH_MAGIC, }; const BUILD_ID: u64 = 0x0123_4567_89AB_CDEF;
maps/src/main/rust/src/graph_zsec.rs
diff --git a/maps/src/main/rust/src/graph_zsec.rs b/maps/src/main/rust/src/graph_zsec.rsindex c0468232a0..c56564f0d3 100644--- a/maps/src/main/rust/src/graph_zsec.rs+++ b/maps/src/main/rust/src/graph_zsec.rs@@ -20,11 +20,14 @@ pub(crate) struct ZsecRegion { unsafe impl Send for ZsecRegion {} unsafe impl Sync for ZsecRegion {} +type GraphBlockKey = (u64, u32);+type CachedGraphBlock = (GraphBlockKey, std::rc::Rc<Vec<u8>>);+ struct GraphZsecCache {- map: std::collections::HashMap<(u64, u32), std::rc::Rc<Vec<u8>>>,- order: std::collections::VecDeque<(u64, u32)>,+ map: std::collections::HashMap<GraphBlockKey, std::rc::Rc<Vec<u8>>>,+ order: std::collections::VecDeque<GraphBlockKey>, bytes: usize,- last: Option<((u64, u32), std::rc::Rc<Vec<u8>>)>,+ last: Option<CachedGraphBlock>, } thread_local! {
maps/src/main/rust/src/routing/steps/lanes.rs
diff --git a/maps/src/main/rust/src/routing/steps/lanes.rs b/maps/src/main/rust/src/routing/steps/lanes.rsindex 6146156b2d..070a434961 100644--- a/maps/src/main/rust/src/routing/steps/lanes.rs+++ b/maps/src/main/rust/src/routing/steps/lanes.rs@@ -55,7 +55,7 @@ fn osm_mask_to_dir_mask(osm: u16) -> u32 { /// taken maneuver is `taken`. Exact match, with a small tolerance so a dedicated /// left lane also serves a slight/sharp-left maneuver (and symmetrically right). fn lane_serves(dir_mask: u32, taken: i32) -> bool {- let has = |o: i32| o >= 0 && o < 31 && (dir_mask & (1u32 << o)) != 0;+ let has = |o: i32| (0..31).contains(&o) && (dir_mask & (1u32 << o)) != 0; match taken { 9 => has(9), // STRAIGHT 4 => has(4) || has(1), // TURN_LEFT
maps/src/main/rust/src/state.rs
diff --git a/maps/src/main/rust/src/state.rs b/maps/src/main/rust/src/state.rsindex b9957019c3..28dd530241 100644--- a/maps/src/main/rust/src/state.rs+++ b/maps/src/main/rust/src/state.rs@@ -25,6 +25,12 @@ pub struct RadixHeap { count: u32, } +impl Default for RadixHeap {+ fn default() -> Self {+ Self::new()+ }+}+ impl RadixHeap { pub fn new() -> RadixHeap { RadixHeap {@@ -116,6 +122,12 @@ pub struct RoutingScratchpad { active_pages: Vec<u32>, } +impl Default for RoutingScratchpad {+ fn default() -> Self {+ Self::new()+ }+}+ impl RoutingScratchpad { pub fn new() -> RoutingScratchpad { let mut directory = Vec::with_capacity(DIR_SIZE);
maps/src/main/rust/src/transit_part12.rs
diff --git a/maps/src/main/rust/src/transit_part12.rs b/maps/src/main/rust/src/transit_part12.rsindex a440ba7500..c468a6363b 100644--- a/maps/src/main/rust/src/transit_part12.rs+++ b/maps/src/main/rust/src/transit_part12.rs@@ -26,7 +26,7 @@ fn trip_itinerary_lists_every_stop_with_times() { let idx = one_route_pack().index(); // Vehicle id for route 0, trip 0, today: the packing active_vehicles uses.- let id = (0i64 << 32) | (0i64 << 1) | 0;+ let id = 0; let itin = trip_itinerary(&idx, id, sched(wednesday())).expect("trip 0 runs Wednesday"); assert_eq!(itin.route_name, "N");@@ -51,10 +51,10 @@ let idx = one_route_pack().index(); // Route 9 does not exist; trip 99 neither. assert!(- trip_itinerary(&idx, (9i64 << 32) | (0i64 << 1), sched(wednesday())).is_none()+ trip_itinerary(&idx, 9i64 << 32, sched(wednesday())).is_none() ); assert!(- trip_itinerary(&idx, (0i64 << 32) | (99i64 << 1), sched(wednesday())).is_none()+ trip_itinerary(&idx, 99i64 << 1, sched(wednesday())).is_none() ); }
maps/src/main/rust/src/transit_part14.rs
diff --git a/maps/src/main/rust/src/transit_part14.rs b/maps/src/main/rust/src/transit_part14.rsindex b40e5316d2..70a2835bf7 100644--- a/maps/src/main/rust/src/transit_part14.rs+++ b/maps/src/main/rust/src/transit_part14.rs@@ -88,7 +88,7 @@ let idx = pack.index(); let legs = plan(&idx, 40.0, -120.0, 40.0, -114.0, 25_200, sched(wednesday())) .expect("Friday is within the horizon");- let last = legs.iter().filter(|l| l.kind == LegKind::Ride).last().expect("a ride");+ let last = legs.iter().rfind(|l| l.kind == LegKind::Ride).expect("a ride"); assert_eq!(last.dep_secs, 2 * SECS_PER_DAY + 32_400); }
maps/src/main/rust/src/transit_part5.rs
diff --git a/maps/src/main/rust/src/transit_part5.rs b/maps/src/main/rust/src/transit_part5.rsindex c15455a3d8..3fc507709e 100644--- a/maps/src/main/rust/src/transit_part5.rs+++ b/maps/src/main/rust/src/transit_part5.rs@@ -83,8 +83,8 @@ pub fn active_vehicles( let mut cancelled = false; let mut delay_secs = 0i32; let mut found_delay = false;- for p in 0..n {- let sched_dep = td.start_time as i64 + dep_rel[p] as i64 - day_shift;+ for (p, dep) in dep_rel.iter().enumerate().take(n) {+ let sched_dep = td.start_time as i64 + *dep as i64 - day_shift; if sched_dep < 0 { continue; }
maps/src/main/rust/src/transit_part6.rs
diff --git a/maps/src/main/rust/src/transit_part6.rs b/maps/src/main/rust/src/transit_part6.rsindex 0c5124ac6f..17512596cd 100644--- a/maps/src/main/rust/src/transit_part6.rs+++ b/maps/src/main/rust/src/transit_part6.rs@@ -457,11 +457,6 @@ fn index(&self) -> TransitIndex { TransitIndex::from_bytes(zsec_pack(&self.build_with_version(7), 64)).expect("index loads") }-- /// The same pack as raw v7 sections (planet4's layout).- fn index_v7(&self) -> TransitIndex {- TransitIndex::from_bytes(self.build_with_version(7)).expect("index loads")- } } /// Rewrite a raw TRIX pack as v8: each non-empty section a ZSEC section of `block`-byte
maps/src/main/rust/src/transit_zsec.rs
diff --git a/maps/src/main/rust/src/transit_zsec.rs b/maps/src/main/rust/src/transit_zsec.rsindex a936938102..87acf74feb 100644--- a/maps/src/main/rust/src/transit_zsec.rs+++ b/maps/src/main/rust/src/transit_zsec.rs@@ -13,14 +13,17 @@ static NEXT_TRANSIT_UID: std::sync::atomic::AtomicU64 = std::sync::atomic::Atomi /// Decoded bytes a thread keeps across all indexes (16 MiB per thread, whatever the block size). const TRANSIT_CACHE_BYTES: usize = 16 << 20; +type TransitBlockKey = (u64, u8, u32);+type CachedTransitBlock = (TransitBlockKey, std::rc::Rc<Vec<u8>>);+ struct TransitBlockCache {- map: std::collections::HashMap<(u64, u8, u32), std::rc::Rc<Vec<u8>>>,- order: std::collections::VecDeque<(u64, u8, u32)>,+ map: std::collections::HashMap<TransitBlockKey, std::rc::Rc<Vec<u8>>>,+ order: std::collections::VecDeque<TransitBlockKey>, /// Decoded bytes held in `map`. bytes: usize, /// The last block each section touched: sequential walks (a varint stream, a polyline) /// stay in one block for thousands of reads, interleaved across sections.- last: Vec<Option<((u64, u8, u32), std::rc::Rc<Vec<u8>>)>>,+ last: Vec<Option<CachedTransitBlock>>, } thread_local! {