Trait graph::prelude::ForEachNodeParallelOp
source · pub trait ForEachNodeParallelOp<NI>where
NI: Idx,{
// Required method
fn for_each_node_par<T, F>(
&self,
node_values: &mut [T],
node_fn: F
) -> Result<(), Error>
where T: Send,
F: Fn(&Self, NI, &mut T) + Send + Sync;
}
Expand description
Call a particular function for each node with its corresponding state in parallel.
Required Methods§
sourcefn for_each_node_par<T, F>(
&self,
node_values: &mut [T],
node_fn: F
) -> Result<(), Error>where
T: Send,
F: Fn(&Self, NI, &mut T) + Send + Sync,
fn for_each_node_par<T, F>( &self, node_values: &mut [T], node_fn: F ) -> Result<(), Error>where T: Send, F: Fn(&Self, NI, &mut T) + Send + Sync,
For each node calls node_fn
with the node and its corresponding mutable
state in parallel.
For every node n
in the graph node_fn(&self, n, node_values[n.index()])
will be called.
node_values
must have length exactly equal to the number of nodes in
the graph.
Example
let graph: DirectedCsrGraph<u32> = GraphBuilder::new()
.edges(vec![(0, 1), (0, 2), (1, 2)])
.build();
let mut node_values = vec![0; 3];
graph.
for_each_node_par(&mut node_values, |g, node, node_state| {
*node_state = g.out_degree(node);
});
assert_eq!(node_values[0], 2);
assert_eq!(node_values[1], 1);
assert_eq!(node_values[2], 0);
Object Safety§
This trait is not object safe.