/// Splits operations in parallizable groups by running a naive connected
/// components algorithm.
///
/// Operations that have data depencies are not parallelizable, so end up
/// being grouped together. An operation has a data dependeny on another
/// operation it it interacts with the same account or neuron.
Splits operations in parallizable groups by running a naive connected
components algorithm.

Operations that have data depencies are not parallelizable, so end up
being grouped together. An operation has a data dependeny on another
operation it it interacts with the same account or neuron.
Splits operations in parallizable groups by running a naive connected components algorithm . Operations that have data depencies are not parallelizable so end up being grouped together . An operation has a data dependeny on another operation it it interacts with the same account or neuron .
fn split_parallelizable_operations(operations: &[Operation]) -> Vec<Vec<Operation>> {
        // Build an adjancency list of data items
        let mut adj = BTreeMap::new();
        for operation in operations {
            for it0 in operation.data_dependendencies() {
                let list = adj.entry(it0).or_insert_with(BTreeSet::new);
                for it1 in operation.data_dependendencies() {
                    if it1 != it0 {
                        list.insert(it1);
                    }
                }
            }
        }
        // Do depth first search in the data items and group them together.
        fn dfs(
            key: u64,
            adj: &BTreeMap<u64, BTreeSet<u64>>,
            mut visited: &mut BTreeSet<u64>,
            mut component: &mut BTreeSet<u64>,
        ) {
            visited.insert(key);
            component.insert(key);
            for value in adj.get(&key).unwrap() {
                if !visited.contains(value) {
                    dfs(*value, adj, &mut visited, &mut component);
                }
            }
        }
        // Go through the adjancency list to find the connected components
        let mut components = Vec::new();
        let mut visited = BTreeSet::new();
        for key in adj.keys() {
            if !visited.contains(key) {
                let mut component = BTreeSet::new();
                dfs(*key, &adj, &mut visited, &mut component);
                components.push(component);
            }
        }
        // Now, for each component get back the operations that involve it.
        let mut final_components = Vec::new();
        for component in components {
            let mut final_component = BTreeSet::new();
            for operation in operations {
                for data_item in operation.data_dependendencies() {
                    if component.contains(&data_item) {
                        final_component.insert(operation);
                    }
                }
            }
            final_components.push(
                final_component
                    .iter()
                    .cloned()
                    .cloned()
                    .collect::<Vec<Operation>>(),
            );
        }
        final_components
    }
fn split_parallelizable_operations ( operations : & [ Operation ] ) -> Vec < Vec < Operation > > { // Build an adjancency list of data items let mut adj = BTreeMap :: new ( ) ; for operation in operations { for it0 in operation . data_dependendencies ( ) { let list = adj . entry ( it0 ) . or_insert_with ( BTreeSet :: new ) ; for it1 in operation . data_dependendencies ( ) { if it1 != it0 { list . insert ( it1 ) ; } } } } // Do depth first search in the data items and group them together. fn dfs ( key : u64 , adj : & BTreeMap < u64 , BTreeSet < u64 > > , mut visited : & mut BTreeSet < u64 > , mut component : & mut BTreeSet < u64 > , ) { visited . insert ( key ) ; component . insert ( key ) ; for value in adj . get ( & key ) . unwrap ( ) { if ! visited . contains ( value ) { dfs ( * value , adj , & mut visited , & mut component ) ; } } } // Go through the adjancency list to find the connected components let mut components = Vec :: new ( ) ; let mut visited = BTreeSet :: new ( ) ; for key in adj . keys ( ) { if ! visited . contains ( key ) { let mut component = BTreeSet :: new ( ) ; dfs ( * key , & adj , & mut visited , & mut component ) ; components . push ( component ) ; } } // Now, for each component get back the operations that involve it. let mut final_components = Vec :: new ( ) ; for component in components { let mut final_component = BTreeSet :: new ( ) ; for operation in operations { for data_item in operation . data_dependendencies ( ) { if component . contains ( & data_item ) { final_component . insert ( operation ) ; } } } final_components . push ( final_component . iter ( ) . cloned ( ) . cloned ( ) . collect :: < Vec < Operation > > ( ) , ) ; } final_components }
Splits operations in parallizable groups by running a naive connected
components algorithm.
Splits operations in parallizable groups by running a naive connected components algorithm .
operations
&[Operation]