ultragraph

Crates.io Docs.rs MIT licensed Audit Clippy Tests OpenSSF Best Practices

📣 Goal

Ultragraph aims to simplify working with directed graph data structures by adding more features such as storing and retrieving nodes directly from the graph, getting all neighbors of a node, and some basic algorithm such as shortest path.

🎁 Features

⚡️ Implementation

🚀 Install

Just run:

toml cargo add ultragraph

Alternatively, add the following to your Cargo.toml

toml ultragraph = "current_version"

⭐ Usage

See:

```rust use ultragraph::prelude::*;

[derive(Default, Debug, Copy, Clone, Hash, Eq, PartialEq)]

pub struct Data { x: u8, }

pub fn main() { let mut g = ultragraph::with_capacity::(10);

// Add nodes to the graph
let root_index = g.add_root_node(Data { x: 3 });
let node_a_index = g.add_node(Data { x: 7 });
let node_b_index = g.add_node(Data { x: 9 });
let node_c_index = g.add_node(Data { x: 11 });

// Link nodes together
// Link root node to node a
let res = g.add_edge(root_index, node_a_index);
assert!(res.is_ok());
// Link node a to node b
let res = g.add_edge(node_a_index, node_b_index);
assert!(res.is_ok());
// Link node root to node c
let res = g.add_edge(root_index, node_c_index);
assert!(res.is_ok());

// Get node a
let node = g.get_node(node_a_index);
assert!(node.is_some());

let data = node.unwrap();
assert_eq!(data.x, 7);

// get all outgoing_edges of root node
let neighbors = g.outgoing_edges(root_index).unwrap();

// root node has 2 outgoing_edges: node a and node b
assert_eq!(neighbors.len(), 2);

// neighbors is just a vector of indices
// so you can iterate over them to get the actual nodes
println!("Neighbors of root node: ");
for n in neighbors{
    let node = g.get_node(n).unwrap();
    println!("node: {:?}", node);
}

} ```

🙏 Credits

The project took inspiration from:

👨‍💻👩‍💻 Contribution

Contributions are welcomed especially related to documentation, example code, and fixes. If unsure where to start, just open an issue and ask.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in deep_causality by you, shall be licensed under the MIT licence, without any additional terms or conditions.

📜 Licence

This project is licensed under the MIT license.

💻 Author