pub struct RewriteGraph(/* private fields */);Expand description
A wrapper around a graph
Methods from Deref<Target = Graph<String, String>>§
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Return the number of nodes (also called vertices) in the graph.
Computes in O(1) time.
Sourcepub fn edge_count(&self) -> usize
pub fn edge_count(&self) -> usize
Return the number of edges in the graph.
Computes in O(1) time.
Sourcepub fn is_directed(&self) -> bool
pub fn is_directed(&self) -> bool
Whether the graph has directed edges or not.
Sourcepub fn node_weight(&self, a: NodeIndex<Ix>) -> Option<&N>
pub fn node_weight(&self, a: NodeIndex<Ix>) -> Option<&N>
Access the weight for node a.
If node a doesn’t exist in the graph, return None.
Also available with indexing syntax: &graph[a].
Sourcepub fn edge_weight(&self, e: EdgeIndex<Ix>) -> Option<&E>
pub fn edge_weight(&self, e: EdgeIndex<Ix>) -> Option<&E>
Access the weight for edge e.
If edge e doesn’t exist in the graph, return None.
Also available with indexing syntax: &graph[e].
Sourcepub fn edge_endpoints(
&self,
e: EdgeIndex<Ix>,
) -> Option<(NodeIndex<Ix>, NodeIndex<Ix>)>
pub fn edge_endpoints( &self, e: EdgeIndex<Ix>, ) -> Option<(NodeIndex<Ix>, NodeIndex<Ix>)>
Access the source and target nodes for e.
If edge e doesn’t exist in the graph, return None.
Sourcepub fn neighbors(&self, a: NodeIndex<Ix>) -> Neighbors<'_, E, Ix>
pub fn neighbors(&self, a: NodeIndex<Ix>) -> Neighbors<'_, E, Ix>
Return an iterator of all nodes with an edge starting from a.
Directed: Outgoing edges froma.Undirected: All edges from or toa.
Produces an empty iterator if the node doesn’t exist.
Iterator element type is NodeIndex<Ix>.
Use .neighbors(a).detach() to get a neighbor walker that does
not borrow from the graph.
Sourcepub fn neighbors_directed(
&self,
a: NodeIndex<Ix>,
dir: Direction,
) -> Neighbors<'_, E, Ix>
pub fn neighbors_directed( &self, a: NodeIndex<Ix>, dir: Direction, ) -> Neighbors<'_, E, Ix>
Return an iterator of all neighbors that have an edge between them and
a, in the specified direction.
If the graph’s edges are undirected, this is equivalent to .neighbors(a).
Directed,Outgoing: All edges froma.Directed,Incoming: All edges toa.Undirected: All edges from or toa.
Produces an empty iterator if the node doesn’t exist.
Iterator element type is NodeIndex<Ix>.
For a Directed graph, neighbors are listed in reverse order of their
addition to the graph, so the most recently added edge’s neighbor is
listed first. The order in an Undirected graph is arbitrary.
Use .neighbors_directed(a, dir).detach() to get a neighbor walker that does
not borrow from the graph.
Sourcepub fn neighbors_undirected(&self, a: NodeIndex<Ix>) -> Neighbors<'_, E, Ix>
pub fn neighbors_undirected(&self, a: NodeIndex<Ix>) -> Neighbors<'_, E, Ix>
Return an iterator of all neighbors that have an edge between them and
a, in either direction.
If the graph’s edges are undirected, this is equivalent to .neighbors(a).
DirectedandUndirected: All edges from or toa.
Produces an empty iterator if the node doesn’t exist.
Iterator element type is NodeIndex<Ix>.
Use .neighbors_undirected(a).detach() to get a neighbor walker that does
not borrow from the graph.
Sourcepub fn edges(&self, a: NodeIndex<Ix>) -> Edges<'_, E, Ty, Ix>
pub fn edges(&self, a: NodeIndex<Ix>) -> Edges<'_, E, Ty, Ix>
Return an iterator of all edges of a.
Directed: Outgoing edges froma.Undirected: All edges connected toa.
Produces an empty iterator if the node doesn’t exist.
Iterator element type is EdgeReference<E, Ix>.
Sourcepub fn edges_directed(
&self,
a: NodeIndex<Ix>,
dir: Direction,
) -> Edges<'_, E, Ty, Ix>
pub fn edges_directed( &self, a: NodeIndex<Ix>, dir: Direction, ) -> Edges<'_, E, Ty, Ix>
Return an iterator of all edges of a, in the specified direction.
Directed,Outgoing: All edges froma.Directed,Incoming: All edges toa.Undirected,Outgoing: All edges connected toa, withabeing the source of each edge.Undirected,Incoming: All edges connected toa, withabeing the target of each edge.
Produces an empty iterator if the node a doesn’t exist.
Iterator element type is EdgeReference<E, Ix>.
Sourcepub fn edges_connecting(
&self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
) -> EdgesConnecting<'_, E, Ty, Ix>
pub fn edges_connecting( &self, a: NodeIndex<Ix>, b: NodeIndex<Ix>, ) -> EdgesConnecting<'_, E, Ty, Ix>
Return an iterator over all the edges connecting a and b.
Directed: Outgoing edges froma.Undirected: All edges connected toa.
Iterator element type is EdgeReference<E, Ix>.
Sourcepub fn contains_edge(&self, a: NodeIndex<Ix>, b: NodeIndex<Ix>) -> bool
pub fn contains_edge(&self, a: NodeIndex<Ix>, b: NodeIndex<Ix>) -> bool
Lookup if there is an edge from a to b.
Computes in O(e’) time, where e’ is the number of edges
connected to a (and b, if the graph edges are undirected).
Sourcepub fn find_edge(
&self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
) -> Option<EdgeIndex<Ix>>
pub fn find_edge( &self, a: NodeIndex<Ix>, b: NodeIndex<Ix>, ) -> Option<EdgeIndex<Ix>>
Lookup an edge from a to b.
Computes in O(e’) time, where e’ is the number of edges
connected to a (and b, if the graph edges are undirected).
Sourcepub fn find_edge_undirected(
&self,
a: NodeIndex<Ix>,
b: NodeIndex<Ix>,
) -> Option<(EdgeIndex<Ix>, Direction)>
pub fn find_edge_undirected( &self, a: NodeIndex<Ix>, b: NodeIndex<Ix>, ) -> Option<(EdgeIndex<Ix>, Direction)>
Lookup an edge between a and b, in either direction.
If the graph is undirected, then this is equivalent to .find_edge().
Return the edge index and its directionality, with Outgoing meaning
from a to b and Incoming the reverse,
or None if the edge does not exist.
Sourcepub fn externals(&self, dir: Direction) -> Externals<'_, N, Ty, Ix>
pub fn externals(&self, dir: Direction) -> Externals<'_, N, Ty, Ix>
Return an iterator over either the nodes without edges to them
(Incoming) or from them (Outgoing).
An internal node has both incoming and outgoing edges.
The nodes in .externals(Incoming) are the source nodes and
.externals(Outgoing) are the sinks of the graph.
For a graph with undirected edges, both the sinks and the sources are just the nodes without edges.
The whole iteration computes in O(|V|) time where V is the set of nodes.
Sourcepub fn node_indices(&self) -> NodeIndices<Ix>
pub fn node_indices(&self) -> NodeIndices<Ix>
Return an iterator over the node indices of the graph.
For example, in a rare case where a graph algorithm were not applicable, the following code will iterate through all nodes to find a specific index:
let index = g.node_indices().find(|i| g[*i] == "book").unwrap();Sourcepub fn node_weights(&self) -> NodeWeights<'_, N, Ix>
pub fn node_weights(&self) -> NodeWeights<'_, N, Ix>
Return an iterator yielding immutable access to all node weights.
The order in which weights are yielded matches the order of their node indices.
Sourcepub fn edge_indices(&self) -> EdgeIndices<Ix>
pub fn edge_indices(&self) -> EdgeIndices<Ix>
Return an iterator over the edge indices of the graph
Sourcepub fn edge_references(&self) -> EdgeReferences<'_, E, Ix>
pub fn edge_references(&self) -> EdgeReferences<'_, E, Ix>
Create an iterator over all edges, in indexed order.
Iterator element type is EdgeReference<E, Ix>.
Sourcepub fn edge_weights(&self) -> EdgeWeights<'_, E, Ix>
pub fn edge_weights(&self) -> EdgeWeights<'_, E, Ix>
Return an iterator yielding immutable access to all edge weights.
The order in which weights are yielded matches the order of their edge indices.
Sourcepub fn first_edge(
&self,
a: NodeIndex<Ix>,
dir: Direction,
) -> Option<EdgeIndex<Ix>>
pub fn first_edge( &self, a: NodeIndex<Ix>, dir: Direction, ) -> Option<EdgeIndex<Ix>>
Accessor for data structure internals: the first edge in the given direction.
Sourcepub fn next_edge(
&self,
e: EdgeIndex<Ix>,
dir: Direction,
) -> Option<EdgeIndex<Ix>>
pub fn next_edge( &self, e: EdgeIndex<Ix>, dir: Direction, ) -> Option<EdgeIndex<Ix>>
Accessor for data structure internals: the next edge for the given direction.
Sourcepub fn capacity(&self) -> (usize, usize)
pub fn capacity(&self) -> (usize, usize)
Return the current node and edge capacity of the graph.
Sourcepub fn map<'a, F, G, N2, E2>(
&'a self,
node_map: F,
edge_map: G,
) -> Graph<N2, E2, Ty, Ix>
pub fn map<'a, F, G, N2, E2>( &'a self, node_map: F, edge_map: G, ) -> Graph<N2, E2, Ty, Ix>
Create a new Graph by mapping node and
edge weights to new values.
The resulting graph has the same structure and the same
graph indices as self.
Sourcepub fn filter_map<'a, F, G, N2, E2>(
&'a self,
node_map: F,
edge_map: G,
) -> Graph<N2, E2, Ty, Ix>
pub fn filter_map<'a, F, G, N2, E2>( &'a self, node_map: F, edge_map: G, ) -> Graph<N2, E2, Ty, Ix>
Create a new Graph by mapping nodes and edges.
A node or edge may be mapped to None to exclude it from
the resulting graph.
Nodes are mapped first with the node_map closure, then
edge_map is called for the edges that have not had any endpoint
removed.
The resulting graph has the structure of a subgraph of the original graph.
If no nodes are removed, the resulting graph has compatible node
indices; if neither nodes nor edges are removed, the result has
the same graph indices as self.
Trait Implementations§
Source§impl Clone for RewriteGraph
impl Clone for RewriteGraph
Source§fn clone(&self) -> RewriteGraph
fn clone(&self) -> RewriteGraph
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Deref for RewriteGraph
impl Deref for RewriteGraph
Auto Trait Implementations§
impl Freeze for RewriteGraph
impl RefUnwindSafe for RewriteGraph
impl Send for RewriteGraph
impl Sync for RewriteGraph
impl Unpin for RewriteGraph
impl UnsafeUnpin for RewriteGraph
impl UnwindSafe for RewriteGraph
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> 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>
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