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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
//! Core traits and types used in gryf.
//!
//! The module mostly contains interfaces that storages and graph
//! representations implement. The main traits that represent different levels
//! of graph functionality are
//!
//! * [GraphBase]
//! * [Neighbors]
//! * [VertexSet]
//! * [EdgeSet]
//! * [GraphRef]
//! * [GraphMut]
//! * [GraphAdd]
//! * [GraphFull]
//!
//! The hierarchy and relations between these are depicted on the diagram below
//! (expand the _Trait hierarchy_ box).
//!
//! <details>
//! <summary>Trait hierarchy</summary>
//!
//! <style>svg { width: 100%; height: 100%; }</style>
//!
//! </details>
//!
//! # Common operations
//!
//! ## Create an empty graph
//!
//! ```
//! use gryf::{core::marker::Directed, Graph};
//!
//! // Directed graph with `&str` vertex attributes and `u32` edge attributes.
//! let graph = Graph::<&str, u32, Directed>::new();
//!
//! // Prefer this if the attribute types (`&str`, `u32`) can be inferred
//! // from the vertices and edges addition.
//! let graph = Graph::<&str, u32, _>::new_directed();
//! ```
//!
//! ## Create an empty graph in a specific storage
//!
//! ```
//! use gryf::{core::marker::Undirected, storage::AdjMatrix, Graph};
//!
//! // The last generic type corresponds to the types of vertex/edge IDs.
//! // Using `::default()` chooses the default ID pair.
//! let graph = Graph::<&str, u32, _, _>::new_in(AdjMatrix::<&str, u32, Undirected, _>::default());
//! ```
//!
//! ## Add vertices and edges
//!
//! ```
//! use gryf::Graph;
//!
//! let mut graph = Graph::new_directed();
//!
//! let foo = graph.add_vertex("foo");
//! let bar = graph.add_vertex("bar");
//! let baz = graph.add_vertex("baz");
//!
//! let foobar = graph.add_edge(foo, bar, 3);
//! graph.extend_with_edges([
//! (foo, baz, 5),
//! (bar, baz, 8),
//! ]);
//! ```
//!
//! ```
//! use gryf::{core::marker::Directed, Graph};
//!
//! let vertices = ["foo", "bar", "baz"];
//! let edges = [(0, 1, 3), (0, 2, 5), (1, 2, 8)];
//!
//! let mut graph = Graph::<&str, u32, Directed>::with_capacity(vertices.len(), edges.len());
//! graph.extend_with_vertices(vertices);
//! graph.extend_with_edges(edges);
//! ```
//!
//! ## Basic properties
//!
//! ```
//! use gryf::{
//! core::marker::{Incoming, Outgoing},
//! Graph,
//! };
//!
//! let mut graph = Graph::new_directed();
//!
//! let foo = graph.add_vertex("foo");
//! let bar = graph.add_vertex("bar");
//! let baz = graph.add_vertex("baz");
//! graph.add_edge(foo, bar, 3);
//! graph.add_edge(bar, baz, 5);
//!
//! assert!(graph.is_directed());
//! assert_eq!(graph.vertex_count(), 3);
//! assert_eq!(graph.edge_count(), 2);
//! assert_eq!(graph.degree_directed(bar, Outgoing), 1);
//! assert_eq!(graph.degree_directed(bar, Incoming), 1);
//! assert_eq!(graph.degree_undirected(bar), 2);
//! assert!(graph.contains_vertex(baz));
//! assert!(graph.contains_edge_between(foo, bar));
//! assert!(graph.edge_id(foo, bar).next().is_some());
//! ```
//!
//! ## Elements iteration
//!
//! ```
//! use gryf::{core::id::VertexId, Graph};
//!
//! let mut graph = Graph::new_directed();
//!
//! let foo = graph.add_vertex("foo");
//! let bar = graph.add_vertex("bar");
//! graph.add_edge(foo, bar, 3);
//!
//! let by_id: Vec<VertexId> = graph.vertices_by_id().collect();
//! let attrs: Vec<&str> = graph.vertices().map(|v| *v.attr).collect();
//! ```
//!
//! ## Graph traversal
//!
//! ```
//! use gryf::{core::marker::Outgoing, Graph};
//!
//! let mut graph = Graph::new_directed();
//!
//! let foo = graph.add_vertex("foo");
//! let bar = graph.add_vertex("bar");
//! graph.add_edge(foo, bar, 3);
//!
//! assert_eq!(
//! graph.neighbors_directed(foo, Outgoing).map(|n| n.id).next(),
//! Some(bar)
//! );
//! ```
//!
//! ## Attributes
//!
//! ```
//! use gryf::Graph;
//!
//! let mut graph = Graph::new_directed();
//!
//! let foo = graph.add_vertex("foo");
//! let bar = graph.add_vertex("bar");
//! let foobar = graph.add_edge(foo, bar, 3);
//!
//! assert_eq!(graph.vertex(foo), Some(&"foo"));
//! assert_eq!(graph.edge(foobar), Some(&3));
//! assert_eq!(graph.find_vertex("bar"), Some(bar));
//! *graph.edge_mut(foobar).unwrap() = 5;
//! ```
pub use *;