refactor dijkstra
This commit is contained in:
@@ -23,7 +23,7 @@ impl<T> Debug for dyn Matrix<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Dijkstra<'a, T> {
|
pub struct Dijkstra<'a, T> {
|
||||||
matrix: Box<&'a mut dyn Matrix<T>>,
|
matrix: &'a mut dyn Matrix<T>,
|
||||||
unvisited_with_distance: HashSet<Coordinate>,
|
unvisited_with_distance: HashSet<Coordinate>,
|
||||||
unvisited_without_distance: HashSet<Coordinate>,
|
unvisited_without_distance: HashSet<Coordinate>,
|
||||||
}
|
}
|
||||||
@@ -40,9 +40,9 @@ impl<'a, T> Dijkstra<'a, T>
|
|||||||
where
|
where
|
||||||
T: PartialOrd + Add<Output = T> + Display + Copy + Debug,
|
T: PartialOrd + Add<Output = T> + Display + Copy + Debug,
|
||||||
{
|
{
|
||||||
pub fn new(matrix: Box<&'a mut dyn Matrix<T>>) -> Self {
|
pub fn new(matrix: &'a mut dyn Matrix<T>) -> Self {
|
||||||
let unvisited_with_distance = HashSet::new();
|
let unvisited_with_distance = HashSet::new();
|
||||||
let unvisited_without_distance = Self::initialize_unvisited_set(*matrix, START);
|
let unvisited_without_distance = Self::initialize_unvisited_set(&*matrix, START);
|
||||||
Self {
|
Self {
|
||||||
matrix,
|
matrix,
|
||||||
unvisited_with_distance,
|
unvisited_with_distance,
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ impl Matrix {
|
|||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut matrix = Matrix::load(Path::new(FILENAME));
|
let mut matrix = Matrix::load(Path::new(FILENAME));
|
||||||
let mut dijkstra = Dijkstra::new(Box::new(&mut matrix));
|
let mut dijkstra = Dijkstra::new(&mut matrix);
|
||||||
dijkstra.solve();
|
dijkstra.solve();
|
||||||
let result = matrix
|
let result = matrix
|
||||||
.get((LENGTH - 1, LENGTH - 1))
|
.get((LENGTH - 1, LENGTH - 1))
|
||||||
|
|||||||
Reference in New Issue
Block a user