pub fn execute<G>(&mut self, graph: &G)
    where
        G: provide::Vertices + provide::Neighbors,
    {
        while let Some(start_id) = self.next_start_id() {
            self.time += 1;
            self.stack.push(start_id);
            self.listener.borrow_mut().on_start(self, start_id);

            while let Some(virt_id) = self.stack.pop() {
                let color = self.colors[virt_id];

                match color {
                    Color::White => {
                        self.time += 1;
                        self.discovered[virt_id] = self.time.into();
                        self.listener.borrow_mut().on_white(self, virt_id);

                        self.colors[virt_id] = Color::Gray;

                        let real_id = self.id_map.real_id_of(virt_id);

                        let mut neighbors = graph
                            .neighbors(real_id)
                            .unwrap()
                            .into_iter()
                            .map(|real_id| self.id_map.virt_id_of(real_id))
                            .filter(|virt_id| self.colors[*virt_id] == Color::White)
                            .collect();

                        self.stack.push(virt_id);
                        self.stack.append(&mut neighbors);
                    }
                    Color::Gray => {
                        self.listener.borrow_mut().on_gray(self, virt_id);

                        self.colors[virt_id] = Color::Black;
                        self.time += 1;
                        self.finished[virt_id] = self.time.into();
                        self.listener.borrow_mut().on_black(self, virt_id);
                    }
                    Color::Black => {}
                }
            }
            self.listener.borrow_mut().on_finish(self);
        }
    }
/// Performs Dfs visit and calls the listener on every event.
Performs Dfs visit and calls the listener on every event.
Performs Dfs visit and calls the listener on every event .
pub fn execute<G>(&mut self, graph: &G)
    where
        G: provide::Vertices + provide::Neighbors,
    {
        while let Some(start_id) = self.next_start_id() {
            self.time += 1;
            self.stack.push(start_id);
            self.listener.borrow_mut().on_start(self, start_id);
            while let Some(virt_id) = self.stack.pop() {
                let color = self.colors[virt_id];
                match color {
                    Color::White => {
                        self.time += 1;
                        self.discovered[virt_id] = self.time.into();
                        self.listener.borrow_mut().on_white(self, virt_id);
                        self.colors[virt_id] = Color::Gray;
                        let real_id = self.id_map.real_id_of(virt_id);
                        let mut neighbors = graph
                            .neighbors(real_id)
                            .unwrap()
                            .into_iter()
                            .map(|real_id| self.id_map.virt_id_of(real_id))
                            .filter(|virt_id| self.colors[*virt_id] == Color::White)
                            .collect();
                        self.stack.push(virt_id);
                        self.stack.append(&mut neighbors);
                    }
                    Color::Gray => {
                        self.listener.borrow_mut().on_gray(self, virt_id);
                        self.colors[virt_id] = Color::Black;
                        self.time += 1;
                        self.finished[virt_id] = self.time.into();
                        self.listener.borrow_mut().on_black(self, virt_id);
                    }
                    Color::Black => {}
                }
            }
            self.listener.borrow_mut().on_finish(self);
        }
    }
pub fn execute < G > ( & mut self , graph : & G ) where G : provide :: Vertices + provide :: Neighbors , { while let Some ( start_id ) = self . next_start_id ( ) { self . time += 1 ; self . stack . push ( start_id ) ; self . listener . borrow_mut ( ) . on_start ( self , start_id ) ; while let Some ( virt_id ) = self . stack . pop ( ) { let color = self . colors [ virt_id ] ; match color { Color :: White => { self . time += 1 ; self . discovered [ virt_id ] = self . time . into ( ) ; self . listener . borrow_mut ( ) . on_white ( self , virt_id ) ; self . colors [ virt_id ] = Color :: Gray ; let real_id = self . id_map . real_id_of ( virt_id ) ; let mut neighbors = graph . neighbors ( real_id ) . unwrap ( ) . into_iter ( ) . map ( | real_id | self . id_map . virt_id_of ( real_id ) ) . filter ( | virt_id | self . colors [ * virt_id ] == Color :: White ) . collect ( ) ; self . stack . push ( virt_id ) ; self . stack . append ( & mut neighbors ) ; } Color :: Gray => { self . listener . borrow_mut ( ) . on_gray ( self , virt_id ) ; self . colors [ virt_id ] = Color :: Black ; self . time += 1 ; self . finished [ virt_id ] = self . time . into ( ) ; self . listener . borrow_mut ( ) . on_black ( self , virt_id ) ; } Color :: Black => { } } } self . listener . borrow_mut ( ) . on_finish ( self ) ; } }
Performs Dfs visit and calls the listener on every event.
Performs Dfs visit and calls the listener on every event .
&mut self
graph
&G
&mut self
graph
&G