1
1
use crate :: { completeness:: Completeness , Scope , ScopeGraph } ;
2
+ use std:: cell:: RefCell ;
2
3
use std:: { collections:: HashSet , hash:: Hash } ;
3
4
5
+ #[ derive( Debug ) ]
4
6
pub ( super ) struct CriticalEdgeSet < LABEL > {
5
- open_edges : Vec < HashSet < LABEL > > ,
7
+ open_edges : RefCell < Vec < HashSet < LABEL > > > ,
6
8
}
7
9
8
10
impl < LABEL > Default for CriticalEdgeSet < LABEL > {
@@ -14,18 +16,18 @@ impl<LABEL> Default for CriticalEdgeSet<LABEL> {
14
16
}
15
17
16
18
impl < LABEL > CriticalEdgeSet < LABEL > {
17
- pub ( super ) fn init_scope ( & mut self , edges : HashSet < LABEL > ) {
18
- self . open_edges . push ( edges)
19
+ pub ( super ) fn init_scope ( & self , edges : HashSet < LABEL > ) {
20
+ self . open_edges . borrow_mut ( ) . push ( edges)
19
21
}
20
22
}
21
23
22
24
impl < LABEL : Hash + Eq > CriticalEdgeSet < LABEL > {
23
25
pub fn is_open ( & self , scope : Scope , lbl : & LABEL ) -> bool {
24
- self . open_edges [ scope. 0 ] . contains ( lbl)
26
+ self . open_edges . borrow ( ) [ scope. 0 ] . contains ( lbl)
25
27
}
26
28
27
- pub ( super ) fn close ( & mut self , scope : Scope , lbl : & LABEL ) -> bool {
28
- self . open_edges [ scope. 0 ] . remove ( lbl)
29
+ pub ( super ) fn close ( & self , scope : Scope , lbl : & LABEL ) -> bool {
30
+ self . open_edges . borrow_mut ( ) [ scope. 0 ] . remove ( lbl)
29
31
}
30
32
}
31
33
@@ -35,7 +37,7 @@ impl<LABEL: Hash + Eq> CriticalEdgeSet<LABEL> {
35
37
///
36
38
/// Should not be called externally, but only from utility function on [`super::ScopeGraph`].
37
39
pub trait CriticalEdgeBasedCompleteness < LABEL , DATA > : Completeness < LABEL , DATA > {
38
- fn init_scope_with ( & mut self , open_edges : HashSet < LABEL > ) ;
40
+ fn init_scope_with ( & self , open_edges : HashSet < LABEL > ) ;
39
41
}
40
42
41
43
/// Error returned when attempting to add an edge with a label that is already closed in that scope.
@@ -46,15 +48,15 @@ pub struct EdgeClosedError<LABEL> {
46
48
}
47
49
48
50
/// Value returned when a query cannot yet be computed because some edge it depends on is still closed.
49
- #[ derive( Debug , Copy , Clone ) ]
51
+ #[ derive( Debug , Copy , Clone , Hash , PartialEq , Eq ) ]
50
52
pub struct Delay < LABEL > {
51
53
pub scope : Scope ,
52
54
pub label : LABEL ,
53
55
}
54
56
55
57
pub ( crate ) type EdgesOrDelay < EDGES , LABEL > = Result < EDGES , Delay < LABEL > > ;
56
58
57
- impl < LABEL : Hash + Eq , DATA , CMPL > ScopeGraph < LABEL , DATA , CMPL >
59
+ impl < ' sg , LABEL : Hash + Eq , DATA , CMPL > ScopeGraph < ' sg , LABEL , DATA , CMPL >
58
60
where
59
61
CMPL : CriticalEdgeBasedCompleteness < LABEL , DATA > ,
60
62
{
@@ -65,22 +67,19 @@ where
65
67
{
66
68
let scope = self . inner_scope_graph . add_scope ( data) ;
67
69
self . completeness
68
- . borrow_mut ( )
69
- . init_scope_with ( HashSet :: from_iter ( open_edges) ) ;
70
+ . init_scope_with ( open_edges. into_iter ( ) . collect ( ) ) ;
70
71
scope
71
72
}
72
73
73
74
/// Adds a new scope with no open edges.
74
75
pub fn add_scope_closed ( & mut self , data : DATA ) -> Scope {
75
76
let scope = self . inner_scope_graph . add_scope ( data) ;
76
- self . completeness
77
- . borrow_mut ( )
78
- . init_scope_with ( HashSet :: new ( ) ) ;
77
+ self . completeness . init_scope_with ( HashSet :: new ( ) ) ;
79
78
scope
80
79
}
81
80
}
82
81
83
- impl < LABEL : Hash + Eq , DATA , CMPL > ScopeGraph < LABEL , DATA , CMPL >
82
+ impl < ' sg , LABEL : Hash + Eq , DATA , CMPL > ScopeGraph < ' sg , LABEL , DATA , CMPL >
84
83
where
85
84
DATA : Default ,
86
85
CMPL : CriticalEdgeBasedCompleteness < LABEL , DATA > ,
0 commit comments