generic-floyd-warshall

Crates.iogeneric-floyd-warshall
lib.rsgeneric-floyd-warshall
version0.2.0
sourcesrc
created_at2020-09-30 14:03:47.105585
updated_at2020-10-04 03:13:09.032653
descriptionA generic implementation of the Floyd-Warshall algorithm for array-like types.
homepage
repository
max_upload_size
id294618
size5,950
Joseph Quinn (quinnjr)

documentation

README

Generic Floyd-Warshall Algorithm

generic-floyd-warshallis 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.

Commit count: 0

cargo fmt