40 lines
1 KiB
Rust
40 lines
1 KiB
Rust
use factorio_graph::priority_queue::{PriorityQueue, fibonacci_heap::FibonacciHeap};
|
|
use std::fmt::Debug;
|
|
|
|
fn test_loop<P>()
|
|
where
|
|
P: PriorityQueue<u16> + Debug,
|
|
{
|
|
let mut input = String::new();
|
|
|
|
let mut p = P::new();
|
|
|
|
let mut handles = Vec::new();
|
|
|
|
loop {
|
|
input.clear();
|
|
let _ = std::io::stdin().read_line(&mut input);
|
|
|
|
let (cmd, arg) = input.trim().split_once(' ').unwrap_or((input.trim(), ""));
|
|
// dbg!(cmd, arg);
|
|
|
|
match cmd {
|
|
"i" => handles.push(p.insert(arg.parse::<u16>().unwrap())),
|
|
"m" => println!("{:?}", p.pop_min()),
|
|
"d" => {
|
|
let (a, b) = arg.split_once(' ').unwrap();
|
|
let h = &handles[a.parse::<usize>().unwrap()];
|
|
let n = b.parse::<u16>().unwrap();
|
|
p.decrease_key(h, |f| *f = n);
|
|
}
|
|
"p" => {
|
|
dbg!(&p);
|
|
}
|
|
_ => println!("Unknown command."),
|
|
}
|
|
}
|
|
}
|
|
|
|
fn main() {
|
|
test_loop::<FibonacciHeap<u16>>()
|
|
}
|