pub fn compute_predecessors(&self) -> Result<FxHashMap<usize, FxHashSet<usize>>> {
        let mut predecessors: FxHashMap<usize, FxHashSet<usize>> = FxHashMap::default();
        let mut queue: VecDeque<usize> = VecDeque::new();

        // initial population
        for vertex in &self.vertices {
            let mut preds = FxHashSet::default();
            for predecessor in &self.predecessors[vertex.0] {
                preds.insert(*predecessor);
            }
            predecessors.insert(*vertex.0, preds);
            queue.push_back(*vertex.0);
        }

        // for every vertex
        while let Some(vertex_index) = queue.pop_front() {
            let this_predecessors = predecessors.get(&vertex_index).unwrap().clone();

            for successor_index in &self.successors[&vertex_index] {
                let successor_predecessors = predecessors.get_mut(successor_index).unwrap();

                let mut changed = false;
                for predecessor in &this_predecessors {
                    changed |= successor_predecessors.insert(*predecessor);
                }

                if changed {
                    queue.push_back(*successor_index);
                }
            }
        }

        Ok(predecessors)
    }
/// Computes predecessors for all vertices in the graph
///
/// The resulting sets include all predecessors for each vertex in the
/// graph, not just immediate predecessors.
///
/// Given A -> B -> C, both A and B will be in the set for C.
Computes predecessors for all vertices in the graph
The resulting sets include all predecessors for each vertex in the
graph, not just immediate predecessors.

Given A -> B -> C, both A and B will be in the set for C.
Computes predecessors for all vertices in the graph The resulting sets include all predecessors for each vertex in the graph not just immediate predecessors . Given A - > B - > C both A and B will be in the set for C .
pub fn compute_predecessors(&self) -> Result<FxHashMap<usize, FxHashSet<usize>>> {
        let mut predecessors: FxHashMap<usize, FxHashSet<usize>> = FxHashMap::default();
        let mut queue: VecDeque<usize> = VecDeque::new();
        // initial population
        for vertex in &self.vertices {
            let mut preds = FxHashSet::default();
            for predecessor in &self.predecessors[vertex.0] {
                preds.insert(*predecessor);
            }
            predecessors.insert(*vertex.0, preds);
            queue.push_back(*vertex.0);
        }
        // for every vertex
        while let Some(vertex_index) = queue.pop_front() {
            let this_predecessors = predecessors.get(&vertex_index).unwrap().clone();
            for successor_index in &self.successors[&vertex_index] {
                let successor_predecessors = predecessors.get_mut(successor_index).unwrap();
                let mut changed = false;
                for predecessor in &this_predecessors {
                    changed |= successor_predecessors.insert(*predecessor);
                }
                if changed {
                    queue.push_back(*successor_index);
                }
            }
        }
        Ok(predecessors)
    }
pub fn compute_predecessors ( & self ) -> Result < FxHashMap < usize , FxHashSet < usize > > > { let mut predecessors : FxHashMap < usize , FxHashSet < usize > > = FxHashMap :: default ( ) ; let mut queue : VecDeque < usize > = VecDeque :: new ( ) ; // initial population for vertex in & self . vertices { let mut preds = FxHashSet :: default ( ) ; for predecessor in & self . predecessors [ vertex . 0 ] { preds . insert ( * predecessor ) ; } predecessors . insert ( * vertex . 0 , preds ) ; queue . push_back ( * vertex . 0 ) ; } // for every vertex while let Some ( vertex_index ) = queue . pop_front ( ) { let this_predecessors = predecessors . get ( & vertex_index ) . unwrap ( ) . clone ( ) ; for successor_index in & self . successors [ & vertex_index ] { let successor_predecessors = predecessors . get_mut ( successor_index ) . unwrap ( ) ; let mut changed = false ; for predecessor in & this_predecessors { changed |= successor_predecessors . insert ( * predecessor ) ; } if changed { queue . push_back ( * successor_index ) ; } } } Ok ( predecessors ) }
Computes predecessors for all vertices in the graph
The resulting sets include all predecessors for each vertex in the
graph, not just immediate predecessors.
Computes predecessors for all vertices in the graph The resulting sets include all predecessors for each vertex in the graph not just immediate predecessors .
&self
&self