diff --git a/src/float_ordering.rs b/src/float_ordering.rs new file mode 100644 index 0000000..bbc0608 --- /dev/null +++ b/src/float_ordering.rs @@ -0,0 +1,18 @@ +use std::cmp::Ordering; + +#[derive(Debug, Clone, PartialEq)] +pub struct NonNan(pub f64); + +impl Eq for NonNan {} + +impl PartialOrd for NonNan { + fn partial_cmp(&self, other: &Self) -> Option { + Some(other.cmp(self)) + } +} + +impl Ord for NonNan { + fn cmp(&self, other: &NonNan) -> Ordering { + self.partial_cmp(other).unwrap() + } +} diff --git a/src/main.rs b/src/main.rs index f9e1f74..da1114b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,15 +3,18 @@ mod airport; mod cmd; mod distance; +mod float_ordering; mod parse; use std::{ cell::RefCell, collections::{hash_map::Entry, HashMap}, env, + f64::INFINITY, rc::Rc, }; +use float_ordering::NonNan; use parse::Record; type NodePointer = Rc>; @@ -23,6 +26,8 @@ struct Node { origin: Rc, destinations: Vec, visited: bool, + source_distance: NonNan, + previous_node: Option, } impl Node { @@ -31,6 +36,8 @@ impl Node { destinations, origin, visited: false, + source_distance: NonNan(INFINITY), + previous_node: None, } } } @@ -134,5 +141,9 @@ fn main() { let args: Vec = env::args().collect(); let (origin_id, destination_id) = cmd::handle_args(args, code_to_id); + // Fetch target nodes + let origin = graph[&origin_id].clone(); + let destination = graph[&destination_id].clone(); + println!("{:#?} {:#?}", graph[&origin_id], graph[&destination_id]); }