1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*!
# graphrs
`graphrs` is a Rust package for the creation, manipulation and analysis of [graphs](https://en.wikipedia.org/wiki/Graph_(discrete_mathematics)).
It allows graphs to be created with support for:
* directed and undirected edges
* multiple edges between two nodes
* self-loops
## Major structs
* [Graph](./struct.Graph.html)
* [Node](./struct.Node.html)
* [Edge](./struct.Edge.html)
## 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"})
});
```
!*/
// run doc tests on the README.md file
extern crate doc_comment;
doc_comment!;
pub use Edge;
pub use ;
pub use Graph;
pub use ;
pub use Node;