1616
1717use  super :: Graph ; 
1818use  super :: iterate:: reverse_post_order; 
19- use  super :: node_vec:: NodeVec ; 
20- use  super :: super :: indexed_vec:: Idx ; 
19+ use  super :: super :: indexed_vec:: { IndexVec ,  Idx } ; 
2120
2221use  std:: fmt; 
2322
@@ -40,13 +39,13 @@ pub fn dominators_given_rpo<G: Graph>(graph: &G,
4039    assert_eq ! ( rpo[ 0 ] ,  start_node) ; 
4140
4241    // compute the post order index (rank) for each node 
43-     let  mut  post_order_rank:  NodeVec < G ,  usize >  = NodeVec :: from_default ( graph) ; 
42+     let  mut  post_order_rank:  IndexVec < G :: Node ,  usize >  = IndexVec :: from_elem_n ( usize :: default ( ) ,   graph. num_nodes ( ) ) ; 
4443    for  ( index,  node)  in  rpo. iter ( ) . rev ( ) . cloned ( ) . enumerate ( )  { 
4544        post_order_rank[ node]  = index; 
4645    } 
4746
48-     let  mut  immediate_dominators:  NodeVec < G ,  Option < G :: Node > >  =
49-         NodeVec :: from_default ( graph) ; 
47+     let  mut  immediate_dominators:  IndexVec < G :: Node ,  Option < G :: Node > >  =
48+         IndexVec :: from_elem_n ( Option :: default ( ) ,   graph. num_nodes ( ) ) ; 
5049    immediate_dominators[ start_node]  = Some ( start_node) ; 
5150
5251    let  mut  changed = true ; 
@@ -58,7 +57,7 @@ pub fn dominators_given_rpo<G: Graph>(graph: &G,
5857            for  pred in  graph. predecessors ( node)  { 
5958                if  immediate_dominators[ pred] . is_some ( )  {  // (*) 
6059                    // (*) dominators for `pred` have been calculated 
61-                     new_idom = intersect_opt ( & post_order_rank, 
60+                     new_idom = intersect_opt :: < G > ( & post_order_rank, 
6261                                             & immediate_dominators, 
6362                                             new_idom, 
6463                                             Some ( pred) ) ; 
@@ -78,24 +77,24 @@ pub fn dominators_given_rpo<G: Graph>(graph: &G,
7877    } 
7978} 
8079
81- fn  intersect_opt < G :  Graph > ( post_order_rank :  & NodeVec < G ,  usize > , 
82-                            immediate_dominators :  & NodeVec < G ,  Option < G :: Node > > , 
80+ fn  intersect_opt < G :  Graph > ( post_order_rank :  & IndexVec < G :: Node ,  usize > , 
81+                            immediate_dominators :  & IndexVec < G :: Node ,  Option < G :: Node > > , 
8382                           node1 :  Option < G :: Node > , 
8483                           node2 :  Option < G :: Node > ) 
8584                           -> Option < G :: Node > 
8685{ 
8786    match  ( node1,  node2)  { 
8887        ( None ,  None )  => None , 
8988        ( Some ( n) ,  None )  | ( None ,  Some ( n) )  => Some ( n) , 
90-         ( Some ( n1) ,  Some ( n2) )  => Some ( intersect ( post_order_rank, 
89+         ( Some ( n1) ,  Some ( n2) )  => Some ( intersect :: < G > ( post_order_rank, 
9190                                               immediate_dominators, 
9291                                               n1, 
9392                                               n2) ) , 
9493    } 
9594} 
9695
97- fn  intersect < G :  Graph > ( post_order_rank :  & NodeVec < G ,  usize > , 
98-                        immediate_dominators :  & NodeVec < G ,  Option < G :: Node > > , 
96+ fn  intersect < G :  Graph > ( post_order_rank :  & IndexVec < G :: Node ,  usize > , 
97+                        immediate_dominators :  & IndexVec < G :: Node ,  Option < G :: Node > > , 
9998                       mut  node1 :  G :: Node , 
10099                       mut  node2 :  G :: Node ) 
101100                       -> G :: Node 
@@ -114,8 +113,8 @@ fn intersect<G: Graph>(post_order_rank: &NodeVec<G, usize>,
114113
115114#[ derive( Clone ,  Debug ) ]  
116115pub  struct  Dominators < G :  Graph >  { 
117-     post_order_rank :  NodeVec < G ,  usize > , 
118-     immediate_dominators :  NodeVec < G ,  Option < G :: Node > > , 
116+     post_order_rank :  IndexVec < G :: Node ,  usize > , 
117+     immediate_dominators :  IndexVec < G :: Node ,  Option < G :: Node > > , 
119118} 
120119
121120impl < G :  Graph >  Dominators < G >  { 
@@ -141,7 +140,7 @@ impl<G: Graph> Dominators<G> {
141140    pub  fn  mutual_dominator_node ( & self ,  node1 :  G :: Node ,  node2 :  G :: Node )  -> G :: Node  { 
142141        assert ! ( self . is_reachable( node1) ,  "node {:?} is not reachable" ,  node1) ; 
143142        assert ! ( self . is_reachable( node2) ,  "node {:?} is not reachable" ,  node2) ; 
144-         intersect ( & self . post_order_rank ,  & self . immediate_dominators ,  node1,  node2) 
143+         intersect :: < G > ( & self . post_order_rank ,  & self . immediate_dominators ,  node1,  node2) 
145144    } 
146145
147146    pub  fn  mutual_dominator < I > ( & self ,  iter :  I )  -> Option < G :: Node > 
@@ -154,13 +153,14 @@ impl<G: Graph> Dominators<G> {
154153            } ) 
155154    } 
156155
157-     pub  fn  all_immediate_dominators ( & self )  -> & NodeVec < G ,  Option < G :: Node > >  { 
156+     pub  fn  all_immediate_dominators ( & self )  -> & IndexVec < G :: Node ,  Option < G :: Node > >  { 
158157        & self . immediate_dominators 
159158    } 
160159
161160    pub  fn  dominator_tree ( & self )  -> DominatorTree < G >  { 
162-         let  mut  children:  NodeVec < G ,  Vec < G :: Node > >  =
163-             NodeVec :: from_default_with_len ( self . immediate_dominators . len ( ) ) ; 
161+         let  elem:  Vec < G :: Node >  = Vec :: new ( ) ; 
162+         let  mut  children:  IndexVec < G :: Node ,  Vec < G :: Node > >  =
163+             IndexVec :: from_elem_n ( elem,  self . immediate_dominators . len ( ) ) ; 
164164        let  mut  root = None ; 
165165        for  ( index,  immed_dom)  in  self . immediate_dominators . iter ( ) . enumerate ( )  { 
166166            let  node = G :: Node :: new ( index) ; 
@@ -204,7 +204,7 @@ impl<'dom, G: Graph> Iterator for Iter<'dom, G> {
204204
205205pub  struct  DominatorTree < G :  Graph >  { 
206206    root :  G :: Node , 
207-     children :  NodeVec < G ,  Vec < G :: Node > > , 
207+     children :  IndexVec < G :: Node ,  Vec < G :: Node > > , 
208208} 
209209
210210impl < G :  Graph >  DominatorTree < G >  { 
0 commit comments