pub struct Graph<V, D: DirectedType> { /* private fields */ }Expand description
A graph data structure supporting both directed and undirected graphs.
§Type Parameters
V- The type of vertex identifiersD- The directedness type (DirectedorUndirected)
§Examples
use std::collections::HashSet;
let mut vertices = HashSet::new();
vertices.insert(1);
vertices.insert(2);
let mut edges = HashSet::new();
edges.insert((1, 2));
let graph = Graph::<usize, Undirected>::new(vertices, edges);Implementations§
Source§impl<V: PartialOrd + Eq + Hash> Graph<V, Undirected>
impl<V: PartialOrd + Eq + Hash> Graph<V, Undirected>
Sourcepub fn new(vertices: HashSet<V>, edges: HashSet<(V, V)>) -> Self
pub fn new(vertices: HashSet<V>, edges: HashSet<(V, V)>) -> Self
Creates a new graph with the given vertices and edges.
For undirected graphs, edges are normalized so that the smaller vertex
(by PartialOrd) is always first in the pair.
§Arguments
vertices- The set of vertices in the graphedges- The set of edges in the graph
§Panics
- If any edge references a vertex not in the vertex set
Source§impl<V: PartialOrd + Eq + Hash> Graph<V, Directed>
impl<V: PartialOrd + Eq + Hash> Graph<V, Directed>
Sourcepub fn new(vertices: HashSet<V>, edges: HashSet<(V, V)>) -> Self
pub fn new(vertices: HashSet<V>, edges: HashSet<(V, V)>) -> Self
Creates a new graph with the given vertices and edges.
For undirected graphs, edges are normalized so that the smaller vertex
(by PartialOrd) is always first in the pair.
§Arguments
vertices- The set of vertices in the graphedges- The set of edges in the graph
§Panics
- If any edge references a vertex not in the vertex set
Trait Implementations§
Source§impl<V: PartialOrd + Eq + Hash + Clone> Collection for Graph<V, Directed>
impl<V: PartialOrd + Eq + Hash + Clone> Collection for Graph<V, Directed>
Source§impl<V: PartialOrd + Eq + Hash + Clone> Collection for Graph<V, Undirected>
impl<V: PartialOrd + Eq + Hash + Clone> Collection for Graph<V, Undirected>
Auto Trait Implementations§
impl<V, D> Freeze for Graph<V, D>
impl<V, D> RefUnwindSafe for Graph<V, D>where
D: RefUnwindSafe,
V: RefUnwindSafe,
impl<V, D> Send for Graph<V, D>
impl<V, D> Sync for Graph<V, D>
impl<V, D> Unpin for Graph<V, D>
impl<V, D> UnwindSafe for Graph<V, D>where
D: UnwindSafe,
V: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more