pub fn compute_loops(&self, head: usize) -> Result<Vec<Loop>> {
        let mut loops: BTreeMap<usize, BTreeSet<usize>> = BTreeMap::new();

        // For each back edge compute the set of nodes part of the loop
        for (tail, header) in self.compute_back_edges(head)? {
            let nodes = loops.entry(header).or_default();
            let mut queue: Vec<usize> = Vec::new();

            nodes.insert(header);

            if nodes.insert(tail) {
                queue.push(tail);
            }

            while let Some(node) = queue.pop() {
                for &predecessor in &self.predecessors[&node] {
                    if nodes.insert(predecessor) {
                        queue.push(predecessor);
                    }
                }
            }
        }

        Ok(loops
            .iter()
            .map(|(&header, nodes)| Loop::new(header, nodes.clone()))
            .collect())
    }
/// Computes the set of natural loops in the graph
Computes the set of natural loops in the graph
Computes the set of natural loops in the graph
pub fn compute_loops(&self, head: usize) -> Result<Vec<Loop>> {
        let mut loops: BTreeMap<usize, BTreeSet<usize>> = BTreeMap::new();
        // For each back edge compute the set of nodes part of the loop
        for (tail, header) in self.compute_back_edges(head)? {
            let nodes = loops.entry(header).or_default();
            let mut queue: Vec<usize> = Vec::new();
            nodes.insert(header);
            if nodes.insert(tail) {
                queue.push(tail);
            }
            while let Some(node) = queue.pop() {
                for &predecessor in &self.predecessors[&node] {
                    if nodes.insert(predecessor) {
                        queue.push(predecessor);
                    }
                }
            }
        }
        Ok(loops
            .iter()
            .map(|(&header, nodes)| Loop::new(header, nodes.clone()))
            .collect())
    }
pub fn compute_loops ( & self , head : usize ) -> Result < Vec < Loop > > { let mut loops : BTreeMap < usize , BTreeSet < usize > > = BTreeMap :: new ( ) ; // For each back edge compute the set of nodes part of the loop for ( tail , header ) in self . compute_back_edges ( head ) ? { let nodes = loops . entry ( header ) . or_default ( ) ; let mut queue : Vec < usize > = Vec :: new ( ) ; nodes . insert ( header ) ; if nodes . insert ( tail ) { queue . push ( tail ) ; } while let Some ( node ) = queue . pop ( ) { for & predecessor in & self . predecessors [ & node ] { if nodes . insert ( predecessor ) { queue . push ( predecessor ) ; } } } } Ok ( loops . iter ( ) . map ( | ( & header , nodes ) | Loop :: new ( header , nodes . clone ( ) ) ) . collect ( ) ) }
Computes the set of natural loops in the graph
Computes the set of natural loops in the graph
&self
head
usize
&self
head
usize