Add fibonacci_heap implementation
This commit is contained in:
parent
6cbb389ee7
commit
d2c1e6d422
6 changed files with 303 additions and 187 deletions
40
examples/priority_queue_test.rs
Normal file
40
examples/priority_queue_test.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use factorio_blueprint::priority_queue::{fibonacci_heap::FibonacciHeap, PriorityQueue};
|
||||
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();
|
||||
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>>()
|
||||
}
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
use factorio_blueprint::belt_finding::{common::Position, Problem};
|
||||
|
||||
fn main() {
|
||||
let mut p = Problem::new(33, 13);
|
||||
|
||||
p.set_blocked_range(1, 3, 2, 5, true);
|
||||
p.set_blocked_range(1, 7, 2, 9, true);
|
||||
|
||||
p.set_blocked(0, 3, true);
|
||||
p.set_blocked(0, 8, true);
|
||||
|
||||
p.set_blocked_range(10, 0, 21, 2, true);
|
||||
p.set_blocked_range(10, 5, 21, 7, true);
|
||||
p.set_blocked_range(10, 10, 21, 12, true);
|
||||
|
||||
p.set_blocked_range(30, 3, 31, 5, true);
|
||||
p.set_blocked_range(30, 7, 31, 9, true);
|
||||
p.set_blocked(32, 3, true);
|
||||
p.set_blocked(32, 9, true);
|
||||
|
||||
p.add_connection(Position::new(3, 3), Position::new(29, 7));
|
||||
p.add_connection(Position::new(3, 4), Position::new(29, 9));
|
||||
p.add_connection(Position::new(3, 5), Position::new(29, 8));
|
||||
|
||||
p.add_connection(Position::new(3, 7), Position::new(29, 3));
|
||||
p.add_connection(Position::new(3, 8), Position::new(29, 5));
|
||||
p.add_connection(Position::new(3, 9), Position::new(29, 4));
|
||||
|
||||
println!("{p}");
|
||||
p.find_path();
|
||||
println!("{p}");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue