Struct calyx_utils::WeightGraph
source · [−]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
sourceimpl<'a, T> WeightGraph<T>where
T: 'a + Eq + Hash + Clone + Ord,
impl<'a, T> WeightGraph<T>where
T: 'a + Eq + Hash + Clone + Ord,
sourcepub fn add_all_edges<C>(&mut self, items: C)where
C: Iterator<Item = &'a T> + Clone,
pub fn add_all_edges<C>(&mut self, items: C)where
C: Iterator<Item = &'a T> + Clone,
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)