Struct bevy_internal::utils::petgraph::stable_graph::WalkNeighbors
source · pub struct WalkNeighbors<Ix> { /* private fields */ }
Expand description
A “walker” object that can be used to step through the edge list of a node.
See .detach() for more information.
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::visit::Dfs;
use petgraph::Incoming;
use petgraph::stable_graph::StableGraph;
let mut gr = StableGraph::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§
source§impl<Ix> WalkNeighbors<Ix>where
Ix: IndexType,
impl<Ix> WalkNeighbors<Ix>where
Ix: IndexType,
sourcepub fn next<N, E, Ty>(
&mut self,
g: &StableGraph<N, E, Ty, Ix>
) -> Option<(EdgeIndex<Ix>, NodeIndex<Ix>)>where
Ty: EdgeType,
pub fn next<N, E, Ty>(
&mut self,
g: &StableGraph<N, E, Ty, Ix>
) -> Option<(EdgeIndex<Ix>, NodeIndex<Ix>)>where
Ty: EdgeType,
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>(
&mut self,
g: &StableGraph<N, E, Ty, Ix>
) -> Option<NodeIndex<Ix>>where
Ty: EdgeType,
pub fn next_edge<N, E, Ty>(
&mut self,
g: &StableGraph<N, E, Ty, Ix>
) -> Option<EdgeIndex<Ix>>where
Ty: EdgeType,
Trait Implementations§
source§impl<Ix> Clone for WalkNeighbors<Ix>where
Ix: IndexType,
impl<Ix> Clone for WalkNeighbors<Ix>where
Ix: IndexType,
source§fn clone(&self) -> WalkNeighbors<Ix>
fn clone(&self) -> WalkNeighbors<Ix>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl<Ix> RefUnwindSafe for WalkNeighbors<Ix>where
Ix: RefUnwindSafe,
impl<Ix> Send for WalkNeighbors<Ix>where
Ix: Send,
impl<Ix> Sync for WalkNeighbors<Ix>where
Ix: Sync,
impl<Ix> Unpin for WalkNeighbors<Ix>where
Ix: Unpin,
impl<Ix> UnwindSafe for WalkNeighbors<Ix>where
Ix: UnwindSafe,
Blanket Implementations§
source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
Return the
T
ShaderType
for self
. When used in AsBindGroup
derives, it is safe to assume that all images in self
exist.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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.