grathe

Crates.iograthe
lib.rsgrathe
version0.2.1
sourcesrc
created_at2021-10-30 12:27:08.126398
updated_at2022-03-14 13:47:27.262297
descriptionA Rust implementation of a GRAph THEory library.
homepagehttps://github.com/AlessioZanga/grathe
repositoryhttps://github.com/AlessioZanga/grathe
max_upload_size
id474370
size459,262
Alessio Zanga (AlessioZanga)

documentation

https://docs.rs/grathe

README

GRATHE

Crates.io build codecov Crates.io Crates.io

A Rust implementation of a GRAph THEory library.

Description

Grathe is a graph theory library that provides a coherent programming experience. Its main goal is to reduce the effort of translating theoretical aspect into practical computation.

How to Usage

Here is a brief example:

use anyhow::Result; // Catch any error.
use grathe::prelude::*; // Frequently used items.

fn main() -> Result<()> {
    // Define an (undirected) graph given its edges.
    let G = Graph::from_edges([
        (0, 1), (1, 2), (3, 4)
    ]);
    
    // Iterate over the vertex set.
    for &x in V!(G) {
        assert!(G.has_vertex(&x));
    }

    // Iterate over the neighbors of `1`.
    for x in Ne!(G, &1) {
        assert!(G.has_edge(x, &1)?);
    }

    // Define a graph with labels, equivalent to Graph::<String>.
    let mut G = Graphl::null();

    // Add a vertex to the graph.
    let x = G.add_vertex("A")?;
    assert!(G.has_vertex(&x));

    // Handle errors in a Rust-compatible way.
    assert!(
        match G.add_vertex(x) {
            Err(_) => true, // Error! Vertex already defined!
            Ok(_) => false, // Ok! Vertex added successfully!
        }
    );

    // Exit with no error.
    Ok(())
}

How to Install

Include grathe into Cargo.toml as dependency.

How to Test

The openblas library is needed. Clone the repository and run the following commands inside of it.

Linux

sudo apt-get install libopenblas-dev

MacOS

brew install openblas

Windows

cargo install cargo-vcpkg
cargo vcpkg -v build
cp target/vcpkg/installed/x64-windows/lib/libopenblas.lib target/vcpkg/installed/x64-windows/lib/openblas.lib

Finally run the tests as usual:

cargo test

References

This repository is based on the following literature:

License

Grathe is dual-licensed under the APACHE LICENSE Version 2 or the MIT LICENSE to be compatible with the Rust project.

Commit count: 318

cargo fmt