2
2
//! paper "Fast Decision Procedures Based on Congruence Closure" by Nelson
3
3
//! and Oppen, JACM 1980.
4
4
5
- use graph:: { self , Graph , NodeIndex } ;
5
+ use petgraph:: Direction ;
6
+ use petgraph:: graph:: { Graph , NodeIndex } ;
6
7
use std:: collections:: HashMap ;
7
8
use std:: fmt:: Debug ;
8
9
use std:: hash:: Hash ;
9
- use std:: iter;
10
10
use unify:: { UnifyKey , UnifyValue , InfallibleUnifyValue , UnificationTable , UnionedKeys } ;
11
11
12
12
#[ cfg( test) ]
@@ -54,11 +54,11 @@ impl Token {
54
54
}
55
55
56
56
fn from_node ( node : NodeIndex ) -> Token {
57
- Token { index : node. 0 as u32 }
57
+ Token { index : node. index ( ) as u32 }
58
58
}
59
59
60
60
fn node ( & self ) -> NodeIndex {
61
- NodeIndex ( self . index as usize )
61
+ NodeIndex :: new ( self . index as usize )
62
62
}
63
63
}
64
64
@@ -134,7 +134,7 @@ impl<K: Key> CongruenceClosure<K> {
134
134
135
135
/// Return the key for a given token
136
136
pub fn key ( & self , token : Token ) -> & K {
137
- self . graph . node_data ( token. node ( ) )
137
+ & self . graph [ token. node ( ) ]
138
138
}
139
139
140
140
/// Indicates they `key1` and `key2` are equivalent.
@@ -281,7 +281,7 @@ impl<'cc, K: Key> Iterator for MergedKeys<'cc, K> {
281
281
fn next ( & mut self ) -> Option < Self :: Item > {
282
282
self . iterator
283
283
. next ( )
284
- . map ( |token| self . graph . node_data ( token. node ( ) ) . clone ( ) )
284
+ . map ( |token| self . graph [ token. node ( ) ] . clone ( ) )
285
285
}
286
286
}
287
287
@@ -316,7 +316,7 @@ impl<'a, K: Key> Algorithm<'a, K> {
316
316
let graph = self . graph ;
317
317
self . table
318
318
. unioned_keys ( u)
319
- . flat_map ( |k| graph. predecessor_nodes ( k. node ( ) ) )
319
+ . flat_map ( |k| graph. neighbors_directed ( k. node ( ) , Direction :: Incoming ) )
320
320
. map ( |i| Token :: from_node ( i) )
321
321
. collect ( )
322
322
}
@@ -352,7 +352,7 @@ impl<'a, K: Key> Algorithm<'a, K> {
352
352
}
353
353
354
354
fn key ( & self , u : Token ) -> & ' a K {
355
- self . graph . node_data ( u. node ( ) )
355
+ & self . graph [ u. node ( ) ]
356
356
}
357
357
358
358
// Compare the local data, not considering successor nodes. So e.g
@@ -364,7 +364,7 @@ impl<'a, K: Key> Algorithm<'a, K> {
364
364
}
365
365
366
366
fn token_kind ( & self , u : Token ) -> KeyKind {
367
- self . graph . node_data ( u. node ( ) ) . key_kind ( )
367
+ self . graph [ u. node ( ) ] . key_kind ( )
368
368
}
369
369
370
370
fn unioned ( & mut self , u : Token , v : Token ) -> bool {
@@ -409,28 +409,9 @@ impl<'a, K: Key> Algorithm<'a, K> {
409
409
}
410
410
}
411
411
412
- fn successors ( & self , token : Token ) -> iter:: Map < graph:: AdjacentTargets < ' a , K , ( ) > ,
413
- fn ( NodeIndex ) -> Token > {
412
+ fn successors ( & self , token : Token ) -> impl Iterator < Item = Token > + ' a {
414
413
self . graph
415
- . successor_nodes ( token. node ( ) )
414
+ . neighbors_directed ( token. node ( ) , Direction :: Outgoing )
416
415
. map ( Token :: from_node)
417
416
}
418
-
419
- fn predecessors ( & self , token : Token ) -> iter:: Map < graph:: AdjacentSources < ' a , K , ( ) > ,
420
- fn ( NodeIndex ) -> Token > {
421
- self . graph
422
- . predecessor_nodes ( token. node ( ) )
423
- . map ( Token :: from_node)
424
- }
425
-
426
- /// If `token` has been unioned with something generative, returns
427
- /// `Ok(u)` where `u` is the generative token. Otherwise, returns
428
- /// `Err(v)` where `v` is the root of `token`.
429
- fn normalize_to_generative ( & mut self , token : Token ) -> Result < Token , Token > {
430
- let token = self . table . find ( token) ;
431
- match self . token_kind ( token) {
432
- Generative => Ok ( token) ,
433
- Applicative => Err ( token) ,
434
- }
435
- }
436
417
}
0 commit comments