graphed

Crates.iographed
lib.rsgraphed
version0.3.0
sourcesrc
created_at2023-07-13 21:36:54.698156
updated_at2023-08-12 13:08:42.075054
descriptionA crate to implement graph-based functionality
homepage
repositoryhttps://github.com/adiepenbrock/graphed
max_upload_size
id915661
size41,822
Andreas Diepenbrock (adiepenbrock)

documentation

README

graphed

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.

Installation

To use graphed in your project, you have to add the graphed crate to your Cargo.toml file.

[dependencies]
graphed = "0.1.0"

Usage

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

Contributions are welcome! Please open an issue or submit a pull request if you have any improvements to the library.

Commit count: 19

cargo fmt