Refactor common types.

This commit is contained in:
hal8174 2024-08-21 20:56:03 +02:00
parent f284b692cc
commit 48419b4674
14 changed files with 376 additions and 250 deletions

View file

@ -1,12 +1,13 @@
use crate::common::color::COLORS;
use crate::graph::wheighted_graph::WheightedGraph;
use crate::misc::Map;
use crate::{
graph::wheighted_graph::shortest_path::dijkstra, priority_queue::fibonacci_heap::FibonacciHeap,
};
use std::ops::Index;
use termcolor::{Color, ColorSpec};
use termcolor::ColorSpec;
use self::common::{print_map, Direction, Position, PositionType};
use self::common::print_map;
use crate::prelude::*;
pub mod brute_force;
pub mod common;
@ -128,25 +129,6 @@ impl Problem {
}
}
pub static COLORS: Cyclic<Color, 6> = Cyclic([
Color::Red,
Color::Green,
Color::Yellow,
Color::Blue,
Color::Magenta,
Color::Cyan,
]);
pub struct Cyclic<T, const N: usize>([T; N]);
impl<T, const N: usize> Index<usize> for Cyclic<T, N> {
type Output = T;
fn index(&self, index: usize) -> &Self::Output {
&self.0[index % N]
}
}
struct MapInternal<'a> {
map: &'a Map<Field>,
end: (Position, Direction),
@ -215,10 +197,8 @@ impl Problem {
}
pub mod problems {
use super::{
common::{Direction, Position},
Problem,
};
use super::Problem;
use crate::prelude::*;
pub fn simple() -> Problem {
let mut p = Problem::new(5, 3);