From 4d41e049717dea654207a0d44be782070a13dd93 Mon Sep 17 00:00:00 2001 From: Felix Buehler Date: Sun, 9 Jul 2023 21:12:31 +0200 Subject: [PATCH] fix lint --- pre/src/contraction.rs | 35 ++++++++++----------- pre/src/offset.rs | 8 ++--- pre/src/ordering.rs | 25 +++++++-------- pre/src/osm_pbf.rs | 2 +- web/src/bidijkstra.rs | 71 +++++++++++++++++++++--------------------- web/src/main.rs | 6 ++-- 6 files changed, 72 insertions(+), 75 deletions(-) diff --git a/pre/src/contraction.rs b/pre/src/contraction.rs index 32f9165..53d48d6 100644 --- a/pre/src/contraction.rs +++ b/pre/src/contraction.rs @@ -36,7 +36,7 @@ pub fn calc_shortcuts( let pair = (source_node, target_node); let lower_edges = (*source_edge, *target_edge); if let Some(old_minima) = minimum_neighbor_distances.get_mut(&pair) { - if (*old_minima).0 > weight { + if (old_minima).0 > weight { *old_minima = (weight, lower_edges); } } else { @@ -75,9 +75,9 @@ pub fn calc_shortcuts( } fn remove_redundant_edges( - mut edges: &mut Vec, - mut up_offset: &mut Vec, - mut down_offset: &mut Vec, + edges: &mut Vec, + up_offset: &mut Vec, + down_offset: &mut Vec, down_index: &mut Vec, amount_nodes: usize, ) { @@ -119,8 +119,7 @@ fn remove_redundant_edges( } // update graph - *down_index = - offset::generate_offsets(&mut edges, &mut up_offset, &mut down_offset, amount_nodes); + *down_index = offset::generate_offsets(edges, up_offset, down_offset, amount_nodes); } fn sort_edges_ranked( @@ -180,10 +179,10 @@ fn revert_indices(edges: &mut Vec) { /// run full contraction pub fn run_contraction( nodes: &mut Vec, - mut edges: &mut Vec, - mut up_offset: &mut Vec, - mut down_offset: &mut Vec, - mut down_index: &mut Vec, + edges: &mut Vec, + up_offset: &mut Vec, + down_offset: &mut Vec, + down_index: &mut Vec, ) { let amount_nodes: usize = nodes.len(); // for keeping track of new created edge_ids @@ -318,8 +317,7 @@ pub fn run_contraction( edges.par_extend(&shortcuts); // recalc edge-indices - *down_index = - offset::generate_offsets(&mut edges, &mut up_offset, &mut down_offset, amount_nodes); + *down_index = offset::generate_offsets(edges, up_offset, down_offset, amount_nodes); // move I to their Level for node in &minimas { @@ -346,9 +344,9 @@ pub fn run_contraction( // remove never used edges remove_redundant_edges( &mut resulting_edges, - &mut up_offset, - &mut down_offset, - &mut down_index, + up_offset, + down_offset, + down_index, amount_nodes, ); @@ -358,14 +356,13 @@ pub fn run_contraction( *edges = resulting_edges; // and calculate the offsets - *down_index = - offset::generate_offsets(&mut edges, &mut up_offset, &mut down_offset, amount_nodes); + *down_index = offset::generate_offsets(edges, up_offset, down_offset, amount_nodes); // sort edges from top to down ranks for bidijkstra - sort_edges_ranked(&mut edges, down_offset, &mut down_index, nodes); + sort_edges_ranked(edges, down_offset, down_index, nodes); // revert the ids back to usual ids - revert_indices(&mut edges); + revert_indices(edges); } #[cfg(test)] diff --git a/pre/src/offset.rs b/pre/src/offset.rs index d041020..25ebb9a 100644 --- a/pre/src/offset.rs +++ b/pre/src/offset.rs @@ -13,8 +13,8 @@ fn fill_offset(edges: Vec, offset: &mut Vec) { /// make sure edges are already sorted!! pub fn generate_offsets_unstable( edges: &mut Vec, - mut up_offset: &mut Vec, - mut down_offset: &mut Vec, + up_offset: &mut Vec, + down_offset: &mut Vec, amount_nodes: usize, ) -> Vec { up_offset.clear(); @@ -24,12 +24,12 @@ pub fn generate_offsets_unstable( // generate up edges let sources: Vec = edges.iter().map(|x| x.source).rev().collect(); - fill_offset(sources, &mut up_offset); + fill_offset(sources, up_offset); // generate down edges, but without sorting edges // first collect offsets let targets: Vec = edges.iter().map(|x| x.target).rev().collect(); - fill_offset(targets, &mut down_offset); + fill_offset(targets, down_offset); let mut down_index = vec![INVALID_EDGE; edges.len()]; // fill offsets, where not already filled for (i, edge) in edges.iter().enumerate() { diff --git a/pre/src/ordering.rs b/pre/src/ordering.rs index cfe3661..7ad9455 100644 --- a/pre/src/ordering.rs +++ b/pre/src/ordering.rs @@ -8,7 +8,7 @@ pub fn node_degree(node: NodeId, up_offset: &[EdgeId], down_offset: &[EdgeId]) - #[allow(clippy::too_many_arguments)] fn edge_difference( node: NodeId, - mut dijkstra: &mut dijkstra::Dijkstra, + dijkstra: &mut dijkstra::Dijkstra, shortcut_id: &AtomicUsize, edges: &[Way], up_offset: &[EdgeId], @@ -18,7 +18,7 @@ fn edge_difference( ) -> isize { let shortcuts = contraction::calc_shortcuts( node, - &mut dijkstra, + dijkstra, edges, up_offset, down_offset, @@ -33,7 +33,7 @@ fn edge_difference( #[allow(clippy::too_many_arguments)] pub fn calculate_single_heuristic( node: NodeId, - mut dijkstra: &mut dijkstra::Dijkstra, + dijkstra: &mut dijkstra::Dijkstra, deleted_neighbors: &[Weight], shortcut_id: &AtomicUsize, edges: &[Way], @@ -45,7 +45,7 @@ pub fn calculate_single_heuristic( deleted_neighbors[node] as isize + edge_difference( node, - &mut dijkstra, + dijkstra, shortcut_id, edges, up_offset, @@ -72,7 +72,7 @@ pub fn calculate_heuristics( heuristics.push(AtomicIsize::new(0)); } - let mut nodes: Vec = (0..amount_nodes).into_iter().collect(); + let mut nodes: Vec = (0..amount_nodes).collect(); let thread_count = num_cpus::get(); let chunk_size = (amount_nodes + thread_count - 1) / thread_count; @@ -94,7 +94,7 @@ pub fn calculate_heuristics( down_index, rank, ); - heuristics[*node as usize].store(new_value, Ordering::Relaxed); + heuristics[*node].store(new_value, Ordering::Relaxed); } }); } @@ -107,7 +107,7 @@ pub fn calculate_heuristics( #[allow(clippy::too_many_arguments)] pub fn update_neighbor_heuristics( mut neighbors: Vec, - heuristics: &mut Vec, + heuristics: &mut [AtomicIsize], deleted_neighbors: &[Weight], shortcut_id: &AtomicUsize, rank: usize, @@ -137,7 +137,7 @@ pub fn update_neighbor_heuristics( down_index, rank, ); - heuristics[*neighbor as usize].store(new_value, Ordering::Relaxed); + heuristics[*neighbor].store(new_value, Ordering::Relaxed); } }); } @@ -155,16 +155,15 @@ pub fn get_independent_set( down_offset: &[EdgeId], down_index: &[NodeId], ) -> Vec { - let subset: Vec; let mut remaining_nodes_vector: Vec = remaining_nodes.iter().copied().collect(); - if remaining_nodes.len() > 10_000 { + let subset: Vec = if remaining_nodes.len() > 10_000 { // sort remaining_nodes via heuristic remaining_nodes_vector.par_sort_by_key(|&node| heuristics[node].load(Ordering::Relaxed)); // take lower 1/4 - subset = (&remaining_nodes_vector[0..remaining_nodes_vector.len() / 4]).to_vec(); + (remaining_nodes_vector[0..remaining_nodes_vector.len() / 4]).to_vec() } else { - subset = remaining_nodes_vector; - } + remaining_nodes_vector + }; minimas_bool.unvisit_all(); // mark all neighbors with greater equal value as invalid diff --git a/pre/src/osm_pbf.rs b/pre/src/osm_pbf.rs index 965a2aa..c997669 100644 --- a/pre/src/osm_pbf.rs +++ b/pre/src/osm_pbf.rs @@ -10,7 +10,7 @@ pub fn get_pbf(filename: &str) -> osmpbfreader::OsmPbfReader { println!("{} not found", filename); std::process::exit(1); } - let r = File::open(&path).unwrap(); + let r = File::open(path).unwrap(); OsmPbfReader::new(r) } diff --git a/web/src/bidijkstra.rs b/web/src/bidijkstra.rs index e8a7664..6841db3 100644 --- a/web/src/bidijkstra.rs +++ b/web/src/bidijkstra.rs @@ -178,47 +178,18 @@ impl Dijkstra { } // walk shortcuts from meeting point to end - fn walk_down(&self, edge: EdgeId, is_upwards: bool, mut path: &mut Vec, edges: &[Way]) { - self.resolve_edge(edge, &mut path, is_upwards, edges); + fn walk_down(&self, edge: EdgeId, is_upwards: bool, path: &mut Vec, edges: &[Way]) { + resolve_edge(edge, path, is_upwards, edges); let current_edge = edges[edge]; - let prev; - if is_upwards { - prev = self.dist_up[current_edge.source]; + let prev = if is_upwards { + self.dist_up[current_edge.source] } else { - prev = self.dist_down[current_edge.target]; - } + self.dist_down[current_edge.target] + }; if let Some(child) = prev.1 { - self.walk_down(child, is_upwards, &mut path, edges); - } - } - - /// resolve shortcuts to original edges - fn resolve_edge( - &self, - edge: EdgeId, - mut path: &mut Vec, - is_upwards: bool, - edges: &[Way], - ) { - match (&edges[edge].contrated_previous, &edges[edge].contrated_next) { - (Some(previous), Some(next)) => { - if is_upwards { - self.resolve_edge(*next, &mut path, is_upwards, edges); - self.resolve_edge(*previous, &mut path, is_upwards, edges); - } else { - self.resolve_edge(*previous, &mut path, is_upwards, edges); - self.resolve_edge(*next, &mut path, is_upwards, edges); - } - } - _ => { - if is_upwards { - path.push(edges[edge].source) - } else { - path.push(edges[edge].target) - } - } + self.walk_down(child, is_upwards, path, edges); } } @@ -267,3 +238,31 @@ impl Dijkstra { false } } + +/// resolve shortcuts to original edges +fn resolve_edge( + // &self, + edge: EdgeId, + path: &mut Vec, + is_upwards: bool, + edges: &[Way], +) { + match (&edges[edge].contrated_previous, &edges[edge].contrated_next) { + (Some(previous), Some(next)) => { + if is_upwards { + resolve_edge(*next, path, is_upwards, edges); + resolve_edge(*previous, path, is_upwards, edges); + } else { + resolve_edge(*previous, path, is_upwards, edges); + resolve_edge(*next, path, is_upwards, edges); + } + } + _ => { + if is_upwards { + path.push(edges[edge].source) + } else { + path.push(edges[edge].target) + } + } + } +} diff --git a/web/src/main.rs b/web/src/main.rs index 1957ddb..dd472bf 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -134,7 +134,9 @@ async fn shortest_path( #[actix_web::main] async fn main() -> std::io::Result<()> { - std::env::set_var("RUST_LOG", "info"); + //std::env::set_var("RUST_LOG", "debug"); + std::env::set_var("RUST_LOG", "actix_web=trace"); + std::env::set_var("RUST_BACKTRACE", "1"); env_logger::init(); // read file @@ -154,7 +156,7 @@ async fn main() -> std::io::Result<()> { println!("Starting server at: http://localhost:8080"); HttpServer::new(move || { // initialize thread-local dijkstra - let dijkstra = RefCell::new(Dijkstra::new(amount_nodes)); + let dijkstra = web::Data::new(RefCell::new(Dijkstra::new(amount_nodes))); App::new() .wrap(middleware::Logger::default()) .app_data(web::JsonConfig::default().limit(1024))