Crates.io | graphed |
lib.rs | graphed |
version | 0.3.0 |
source | src |
created_at | 2023-07-13 21:36:54.698156 |
updated_at | 2023-08-12 13:08:42.075054 |
description | A crate to implement graph-based functionality |
homepage | |
repository | https://github.com/adiepenbrock/graphed |
max_upload_size | |
id | 915661 |
size | 41,822 |
graphed
is a library that provides a simple way to create and manipulate graphs in your Rust project. Whether you're working on a data science project, building a recommendation system, or want to visualize your data more intuitively, graphed
makes it easy to get started.
To use graphed
in your project, you have to add the graphed
crate to your Cargo.toml
file.
[dependencies]
graphed = "0.1.0"
To create a graph with two nodes (Node 1 and Node 2) and an edge between them with a value of 1, you can do the following:
use graphed::graph::DiGraph;
let mut gr = DiGraph::<&str, usize>::new();
let idx_n1 = gr.add_node("Node 1");
let idx_n2 = gr.add_node("Node 2");
let _ = gr.add_edge(idx_n1, idx_n2, 1);
If you need a custom node or edge struct, e.g., for additional data, you can specify your structs and use them as the generic parameter of the Graph class. An example with a custom node (CustomNode) and a custom edge (CustomEdge) is shown below:
use graphed::graph::Graph;
pub struct CustomNode(usize);
pub struct CustomEdge(usize);
let mut gr = DiGraph::<CustomNode, CustomEdge>::new();
let idx_n1 = gr.add_node(CustomNode(1));
let idx_n2 = gr.add_node(CustomNode(2));
let _ = gr.add_edge(idx_n1, idx_n2, CustomEdge(123));
Contributions are welcome! Please open an issue or submit a pull request if you have any improvements to the library.