pub struct WeightGraph<T> {
pub index_map: HashMap<T, NodeIndex>,
pub graph: UnMatrix<(), BoolIdx>,
}
Expand description
Weight graph provides a wrapper over a Graph that allows adding edges using
the NodeWeight type T
(petgraph only allows adding edges using NodeIndex
).
Additionally, the edges are not allowed to have any weights.
The internal representation stores a mapping from NodeWeight T
to a
NodeIndex
in the graph.
The underlying petgraph::MatrixGraph
stores ()
for node weights and
a boolean to represent the edges.
Fields§
§index_map: HashMap<T, NodeIndex>
Mapping from T to a unique identifier.
graph: UnMatrix<(), BoolIdx>
Graph representating using identifier.
Implementations§
Source§impl<'a, T> WeightGraph<T>
impl<'a, T> WeightGraph<T>
Sourcepub fn add_all_edges<C>(&mut self, items: C)
pub fn add_all_edges<C>(&mut self, items: C)
Add edges between all given items.
Sourcepub fn contains_node(&self, node: &T) -> bool
pub fn contains_node(&self, node: &T) -> bool
Checks if the node has already been added to the graph.
Sourcepub fn add_node(&mut self, node: T)
pub fn add_node(&mut self, node: T)
Add a new node to the graph. Client code should ensure that duplicate
edges are never added to graph.
Instead of using this method, consider constructing the graph using
From<Iterator<T>>
.
§Panics
(Debug build only) Panics if node is already present in the graph
Sourcepub fn reverse_index(&self) -> HashMap<NodeIndex, T>
pub fn reverse_index(&self) -> HashMap<NodeIndex, T>
Returns a Map from NodeIndex
to T
(the reverse of the index)
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for WeightGraph<T>
impl<T> RefUnwindSafe for WeightGraph<T>where
T: RefUnwindSafe,
impl<T> Send for WeightGraph<T>where
T: Send,
impl<T> Sync for WeightGraph<T>where
T: Sync,
impl<T> Unpin for WeightGraph<T>where
T: Unpin,
impl<T> UnwindSafe for WeightGraph<T>where
T: 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
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>
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>
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