Crates.io | grathe |
lib.rs | grathe |
version | 0.2.1 |
source | src |
created_at | 2021-10-30 12:27:08.126398 |
updated_at | 2022-03-14 13:47:27.262297 |
description | A Rust implementation of a GRAph THEory library. |
homepage | https://github.com/AlessioZanga/grathe |
repository | https://github.com/AlessioZanga/grathe |
max_upload_size | |
id | 474370 |
size | 459,262 |
A Rust implementation of a GRAph THEory library.
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.
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(())
}
Include grathe
into Cargo.toml
as dependency.
The openblas
library is needed. Clone the repository and run the following commands inside of it.
sudo apt-get install libopenblas-dev
brew install openblas
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
This repository is based on the following literature:
Grathe is dual-licensed under the APACHE LICENSE Version 2 or the MIT LICENSE to be compatible with the Rust project.