Expand description
§graphrs
graphrs
is a Rust package for the creation, manipulation and analysis of graphs.
It allows graphs to be created with support for:
- directed and undirected edges
- multiple edges between two nodes
- self-loops
§Major structs
§Example: create a graph
use graphrs::{Edge, Graph, GraphSpecs, Node};
let nodes = vec![
Node::from_name("n1"),
Node::from_name("n2"),
Node::from_name("n3"),
];
let edges = vec![
Edge::with_weight("n1", "n2", 1.0),
Edge::with_weight("n2", "n1", 2.0),
Edge::with_weight("n1", "n3", 3.0),
Edge::with_weight("n2", "n3", 3.0),
];
let specs = GraphSpecs::directed(); // change this to `::undirected()` to get an undirected graph
let graph = Graph::<&str, ()>::new_from_nodes_and_edges(
nodes,
edges,
specs
);
§Example: create a graph from just edges
use graphrs::{Edge, Graph, GraphSpecs, Node};
let mut graph = Graph::<&str, ()>::new(GraphSpecs::directed_create_missing());
graph.add_edges(vec![
Edge::with_weight("n1", "n2", 1.0),
Edge::with_weight("n2", "n1", 2.0),
Edge::with_weight("n1", "n3", 3.0),
Edge::with_weight("n2", "n3", 3.0),
]);
§Example: create a graph with nodes that have attributes
use graphrs::{Edge, Graph, GraphSpecs, Node};
#[derive(Copy, Clone)]
struct NodeAttribute<'a> {
first_name: &'a str,
last_name: &'a str,
};
let mut graph: Graph<i32, NodeAttribute> = Graph::new(GraphSpecs::undirected());
graph.add_node(Node {
name: 1,
attributes: Some(NodeAttribute {first_name: "Jane", last_name: "Smith"})
});
!
Modules§
Structs§
- Represents a graph edge as (
u
,v
). - If errors occur when creating or processing a
Graph
thisError
struct will be returned. - The
Graph
struct represents a graph of nodes and vertices. It allows graphs to be created with support for: - Specifications for the type of Graph being created and how various situations involving the addition of nodes and edges are handled.
- Represents a graph node, with
name
andattributes
.