Trait graph::graph_ops::ForEachNodeParallelOp[][src]

pub trait ForEachNodeParallelOp<Node: Idx> {
    fn for_each_node_par<T, F>(
        &self,
        node_values: &mut [T],
        node_fn: F
    ) -> Result<(), Error>
    where
        T: Send,
        F: Fn(&Self, Node, &mut T) + Send + Sync
; }
Expand description

Call a particular function for each node with its corresponding state in parallel.

Required methods

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);

Implementors