[−][src]Struct petgraph::graph::WalkNeighbors
A “walker” object that can be used to step through the edge list of a node.
Created with .detach()
.
The walker does not borrow from the graph, so it lets you step through neighbors or incident edges while also mutating graph weights, as in the following example:
use petgraph::{Graph, Incoming}; use petgraph::visit::Dfs; let mut gr = Graph::new(); let a = gr.add_node(0.); let b = gr.add_node(0.); let c = gr.add_node(0.); gr.add_edge(a, b, 3.); gr.add_edge(b, c, 2.); gr.add_edge(c, b, 1.); // step through the graph and sum incoming edges into the node weight let mut dfs = Dfs::new(&gr, a); while let Some(node) = dfs.next(&gr) { // use a detached neighbors walker let mut edges = gr.neighbors_directed(node, Incoming).detach(); while let Some(edge) = edges.next_edge(&gr) { gr[node] += gr[edge]; } } // check the result assert_eq!(gr[a], 0.); assert_eq!(gr[b], 4.); assert_eq!(gr[c], 2.);
Implementations
impl<Ix: IndexType> WalkNeighbors<Ix>
[src]
pub fn next<N, E, Ty: EdgeType>(
&mut self,
g: &Graph<N, E, Ty, Ix>
) -> Option<(EdgeIndex<Ix>, NodeIndex<Ix>)>
[src]
&mut self,
g: &Graph<N, E, Ty, Ix>
) -> Option<(EdgeIndex<Ix>, NodeIndex<Ix>)>
Step to the next edge and its endpoint node in the walk for graph g
.
The next node indices are always the others than the starting point
where the WalkNeighbors
value was created.
For an Outgoing
walk, the target nodes,
for an Incoming
walk, the source nodes of the edge.
pub fn next_node<N, E, Ty: EdgeType>(
&mut self,
g: &Graph<N, E, Ty, Ix>
) -> Option<NodeIndex<Ix>>
[src]
&mut self,
g: &Graph<N, E, Ty, Ix>
) -> Option<NodeIndex<Ix>>
pub fn next_edge<N, E, Ty: EdgeType>(
&mut self,
g: &Graph<N, E, Ty, Ix>
) -> Option<EdgeIndex<Ix>>
[src]
&mut self,
g: &Graph<N, E, Ty, Ix>
) -> Option<EdgeIndex<Ix>>
Trait Implementations
impl<Ix> Clone for WalkNeighbors<Ix> where
Ix: IndexType,
[src]
Ix: IndexType,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Auto Trait Implementations
impl<Ix> RefUnwindSafe for WalkNeighbors<Ix> where
Ix: RefUnwindSafe,
Ix: RefUnwindSafe,
impl<Ix> Send for WalkNeighbors<Ix> where
Ix: Send,
Ix: Send,
impl<Ix> Sync for WalkNeighbors<Ix> where
Ix: Sync,
Ix: Sync,
impl<Ix> Unpin for WalkNeighbors<Ix> where
Ix: Unpin,
Ix: Unpin,
impl<Ix> UnwindSafe for WalkNeighbors<Ix> where
Ix: UnwindSafe,
Ix: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,