diff --git a/examples/priority_queue_test.rs b/examples/priority_queue_test.rs
new file mode 100644
index 0000000..a8a739b
--- /dev/null
+++ b/examples/priority_queue_test.rs
@@ -0,0 +1,40 @@
+use factorio_blueprint::priority_queue::{fibonacci_heap::FibonacciHeap, PriorityQueue};
+use std::fmt::Debug;
+
+fn test_loop
()
+where
+ P: PriorityQueue + 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::().unwrap())),
+ "m" => println!("{:?}", p.pop_min()),
+ "d" => {
+ let (a, b) = arg.split_once(' ').unwrap();
+ let h = &handles[a.parse::().unwrap()];
+ let n = b.parse::().unwrap();
+ p.decrease_key(h, |f| *f = n);
+ }
+ "p" => {
+ dbg!(&p);
+ }
+ _ => println!("Unknown command."),
+ }
+ }
+}
+
+fn main() {
+ test_loop::>()
+}
diff --git a/examples/solve_belt2.rs b/examples/solve_belt2.rs
deleted file mode 100644
index 5b88e0d..0000000
--- a/examples/solve_belt2.rs
+++ /dev/null
@@ -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}");
-}
diff --git a/src/belt_finding/mod.rs b/src/belt_finding/mod.rs
index 666fc8b..feb017f 100644
--- a/src/belt_finding/mod.rs
+++ b/src/belt_finding/mod.rs
@@ -1,7 +1,9 @@
-use crate::graph::wheighted_graph::shortest_path::dijkstra;
use crate::graph::wheighted_graph::WheightedGraph;
use crate::misc::Map;
use crate::priority_queue::BinaryHeap;
+use crate::{
+ graph::wheighted_graph::shortest_path::dijkstra, priority_queue::fibonacci_heap::FibonacciHeap,
+};
use std::ops::Index;
use termcolor::{Color, ColorSpec};
@@ -208,7 +210,7 @@ impl Problem {
for i in 0..self.start.len() {
self.calculate_wheights(i);
let m = MapInternal { map: &self.map };
- let p = dijkstra::>(&m, self.start[i], self.end[i]);
+ let p = dijkstra::>(&m, self.start[i], self.end[i]);
if let Some(p) = p {
self.path[i] = p;
diff --git a/src/graph/wheighted_graph/shortest_path.rs b/src/graph/wheighted_graph/shortest_path.rs
index a6142ce..27887f1 100644
--- a/src/graph/wheighted_graph/shortest_path.rs
+++ b/src/graph/wheighted_graph/shortest_path.rs
@@ -119,7 +119,7 @@ mod test {
graph::wheighted_graph::{
adjacency_list::WheightedAdjacencyList, shortest_path::dijkstra, WheightedGraph,
},
- priority_queue::BinaryHeap,
+ priority_queue::{fibonacci_heap::FibonacciHeap, BinaryHeap},
};
#[test]
@@ -162,6 +162,14 @@ mod test {
dijkstra::>(&a, 0, 6),
None
);
+ assert_eq!(
+ dijkstra::>(&a, 0, 4),
+ Some(vec![0, 1, 2, 5, 4])
+ );
+ assert_eq!(
+ dijkstra::>(&a, 0, 6),
+ None
+ );
}
struct Grid {
diff --git a/src/priority_queue/fibonacci_heap.rs b/src/priority_queue/fibonacci_heap.rs
index dca5da5..a181df0 100644
--- a/src/priority_queue/fibonacci_heap.rs
+++ b/src/priority_queue/fibonacci_heap.rs
@@ -1,186 +1,280 @@
+use std::fmt::Debug;
+
use crate::misc::{Arena, ArenaKey};
use super::PriorityQueue;
-#[derive(Debug)]
-struct FibonacciHeapObject {
- left: ArenaKey,
- right: ArenaKey,
- parent: Option,
- child: Option,
- rank: usize,
- marked: bool,
- data: T,
+type Index = u32;
+
+pub struct FibonacciHeap {
+ min: Option,
+ data: Vec