fn count(&mut self, g: &Graph, start: &str, end: &str) -> usize {
        let start = &name_trans(start);
        let end = &name_trans(end);
        let mut count = 0;
        self.push(g, start, end);
        while let Some(node) = self.stack.pop() {
            self.push(g, &node, end);
            if self.verbose {
                println!("  STACK: {:?} | {}", self.stack, node);
                println!(" STATUS: {:?}", self.status);
            }
            let top = self.status.top().expect("empty status right after push");
            // If we're looking at a node with no children, we've reached the end of a path.
            // If the node is 'end' we've found a valid unique path, otherwise it's a deadend.
            if top.1 == 0 || &node == end {
                // Unroll status to the next branch with more children to visit.
                count = 0;
                'popping: while self.status.len() > 0 {
                    // Accumulate the number of child paths into the current path.
                    if count > 0 {
                        *self.status.subtree_counts.last_mut().unwrap() += count;
                    }
                    let top = self.status.top().unwrap();
                    if top.1 <= 1 {
                        // Now we've completed the subtree: pop it and memoize if possible.
                        let subpath = self.status.path.clone();
                        count = self.status.pop().unwrap().2;
                        // We can only memoize paths ending in a multi-node.
                        if self.verbose {
                            println!(
                                "finished subtree '{}' with {} paths",
                                self.status.path.0, count
                            );
                        }
                        if self.is_multinode(subpath.top().unwrap()) {
                            self.set_count(subpath, count);
                        }
                    } else {
                        *self.status.child_counts.last_mut().unwrap() -= 1;
                        if self.verbose {
                            let top = self.status.top().unwrap();
                            println!("now '{}' has {} children left", top.0, top.1);
                        }
                        break 'popping;
                    }
                }
            }
        }
        count
    }
// Specialized version of visit() which counts paths quicker than visiting them all.
Specialized version of visit() which counts paths quicker than visiting them all.
Specialized version of visit () which counts paths quicker than visiting them all .
fn count(&mut self, g: &Graph, start: &str, end: &str) -> usize {
        let start = &name_trans(start);
        let end = &name_trans(end);
        let mut count = 0;
        self.push(g, start, end);
        while let Some(node) = self.stack.pop() {
            self.push(g, &node, end);
            if self.verbose {
                println!("  STACK: {:?} | {}", self.stack, node);
                println!(" STATUS: {:?}", self.status);
            }
            let top = self.status.top().expect("empty status right after push");
            // If we're looking at a node with no children, we've reached the end of a path.
            // If the node is 'end' we've found a valid unique path, otherwise it's a deadend.
            if top.1 == 0 || &node == end {
                // Unroll status to the next branch with more children to visit.
                count = 0;
                'popping: while self.status.len() > 0 {
                    // Accumulate the number of child paths into the current path.
                    if count > 0 {
                        *self.status.subtree_counts.last_mut().unwrap() += count;
                    }
                    let top = self.status.top().unwrap();
                    if top.1 <= 1 {
                        // Now we've completed the subtree: pop it and memoize if possible.
                        let subpath = self.status.path.clone();
                        count = self.status.pop().unwrap().2;
                        // We can only memoize paths ending in a multi-node.
                        if self.verbose {
                            println!(
                                "finished subtree '{}' with {} paths",
                                self.status.path.0, count
                            );
                        }
                        if self.is_multinode(subpath.top().unwrap()) {
                            self.set_count(subpath, count);
                        }
                    } else {
                        *self.status.child_counts.last_mut().unwrap() -= 1;
                        if self.verbose {
                            let top = self.status.top().unwrap();
                            println!("now '{}' has {} children left", top.0, top.1);
                        }
                        break 'popping;
                    }
                }
            }
        }
        count
    }
fn count ( & mut self , g : & Graph , start : & str , end : & str ) -> usize { let start = & name_trans ( start ) ; let end = & name_trans ( end ) ; let mut count = 0 ; self . push ( g , start , end ) ; while let Some ( node ) = self . stack . pop ( ) { self . push ( g , & node , end ) ; if self . verbose { println ! ( " " self stack node ) ; println ! ( " " self status ) ; } let top = self . status . top ( ) . expect ( " " ) ; // If we're looking at a node with no children, we've reached the end of a path. // If the node is 'end' we've found a valid unique path, otherwise it's a deadend. if top . 1 == 0 || & node == end { // Unroll status to the next branch with more children to visit. count = 0 ; ' popping : while self . status . len ( ) > 0 { // Accumulate the number of child paths into the current path. if count > 0 { * self . status . subtree_counts . last_mut ( ) . unwrap ( ) += count ; } let top = self . status . top ( ) . unwrap ( ) ; if top . 1 <= 1 { // Now we've completed the subtree: pop it and memoize if possible. let subpath = self . status . path . clone ( ) ; count = self . status . pop ( ) . unwrap ( ) . 2 ; // We can only memoize paths ending in a multi-node. if self . verbose { println ! ( " " self status path 0 count ) ; } if self . is_multinode ( subpath . top ( ) . unwrap ( ) ) { self . set_count ( subpath , count ) ; } } else { * self . status . child_counts . last_mut ( ) . unwrap ( ) -= 1 ; if self . verbose { let top = self . status . top ( ) . unwrap ( ) ; println ! ( " " top 0 top 1 ) ; } break ' popping ; } } } } count }
Specialized version of visit() which counts paths quicker than visiting them all.
Specialized version of visit () which counts paths quicker than visiting them all .
&mut self
g
&Graph
start
&str
end
&str