non nan and stuff
This commit is contained in:
parent
3d14f3b3e1
commit
5eeca21c44
2 changed files with 29 additions and 0 deletions
18
src/float_ordering.rs
Normal file
18
src/float_ordering.rs
Normal file
|
@ -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<Ordering> {
|
||||
Some(other.cmp(self))
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for NonNan {
|
||||
fn cmp(&self, other: &NonNan) -> Ordering {
|
||||
self.partial_cmp(other).unwrap()
|
||||
}
|
||||
}
|
11
src/main.rs
11
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<RefCell<Node>>;
|
||||
|
@ -23,6 +26,8 @@ struct Node {
|
|||
origin: Rc<airport::Airport>,
|
||||
destinations: Vec<Destination>,
|
||||
visited: bool,
|
||||
source_distance: NonNan,
|
||||
previous_node: Option<NodePointer>,
|
||||
}
|
||||
|
||||
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<String> = 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]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue