From 5eeca21c447d6d754ddc29f7005889e12429faa5 Mon Sep 17 00:00:00 2001 From: Zynh0722 Date: Wed, 24 Apr 2024 10:00:07 -0700 Subject: [PATCH] non nan and stuff --- src/float_ordering.rs | 18 ++++++++++++++++++ src/main.rs | 11 +++++++++++ 2 files changed, 29 insertions(+) create mode 100644 src/float_ordering.rs 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]); }