Crates.io | generic-floyd-warshall |
lib.rs | generic-floyd-warshall |
version | 0.2.0 |
source | src |
created_at | 2020-09-30 14:03:47.105585 |
updated_at | 2020-10-04 03:13:09.032653 |
description | A generic implementation of the Floyd-Warshall algorithm for array-like types. |
homepage | |
repository | |
max_upload_size | |
id | 294618 |
size | 5,950 |
generic-floyd-warshall
is intended to work with the core array-like primatives and types in the Rust language, like Vectors, so that the array-like types can be used to form matrices and then properly handle the execution of the Floyd-Warshall algorithm on them.
As well, generic-floyd-warshall
is intended to be used with user-defined types that implement std::ops::{ Add, Index, IndexMut }
and std::cmp::PartialOrd
.
fn main() {
let graph = vec![
vec![0.0, f32::INFINITY, -2.0, f32::INFINITY],
vec![4.0, 0.0, 3.0, f32::INFINITY],
vec![f32::INFINITY, f32::INFINITY, 0.0, 2.0],
vec![f32::INFINITY, -1.0, f32::INFINITY, 0.0]
];
let expected = vec![
vec![0.0, -1.0, -2.0, 0.0],
vec![4.0, 0.0, 2.0, 4.0],
vec![5.0, 1.0, 0.0, 2.0],
vec![3.0, -1.0, 1.0, 0.0]
];
let len = graph.len();
let mut calculated = graph.clone();
floyd_warshall(&mut calculated, len);
assert_eq!(expected, calculated);
}
This crate is in an experimental phase. Critique and suggestions for improvement are welcome.