1
1
#[ cfg( feature = "persistent" ) ]
2
2
use dogged:: DVec ;
3
3
use snapshot_vec as sv;
4
- use std:: ops;
5
- use std:: ops:: RangeInclusive ;
4
+ use std:: ops:: { self , Range } ;
6
5
use std:: marker:: PhantomData ;
7
6
8
7
use super :: { VarValue , UnifyKey , UnifyValue } ;
@@ -11,35 +10,31 @@ use super::{VarValue, UnifyKey, UnifyValue};
11
10
#[ allow( type_alias_bounds) ]
12
11
type Key < S : UnificationStore > = <S as UnificationStore >:: Key ;
13
12
14
- pub trait Measurable {
15
- fn len ( & self ) -> usize ;
16
- }
17
-
18
13
/// Largely internal trait implemented by the unification table
19
14
/// backing store types. The most common such type is `InPlace`,
20
15
/// which indicates a standard, mutable unification table.
21
16
pub trait UnificationStore :
22
- ops:: Index < usize , Output = VarValue < Key < Self > > > + Measurable + Clone + Default
17
+ ops:: Index < usize , Output = VarValue < Key < Self > > > + Clone + Default
23
18
{
24
19
type Key : UnifyKey < Value = Self :: Value > ;
25
20
type Value : UnifyValue ;
26
- type Snapshot : Measurable ;
21
+ type Snapshot ;
27
22
28
23
fn start_snapshot ( & mut self ) -> Self :: Snapshot ;
29
24
30
25
fn rollback_to ( & mut self , snapshot : Self :: Snapshot ) ;
31
26
32
27
fn commit ( & mut self , snapshot : Self :: Snapshot ) ;
33
28
34
- fn values_since_snapshot ( & mut self , snapshot : & Self :: Snapshot ) -> RangeInclusive < usize > {
35
- snapshot. len ( ) ..=self . len ( )
36
- }
29
+ fn values_since_snapshot ( & self , snapshot : & Self :: Snapshot ) -> Range < usize > ;
37
30
38
31
fn reset_unifications (
39
32
& mut self ,
40
33
value : impl FnMut ( u32 ) -> VarValue < Self :: Key > ,
41
34
) ;
42
35
36
+ fn len ( & self ) -> usize ;
37
+
43
38
fn push ( & mut self , value : VarValue < Self :: Key > ) ;
44
39
45
40
fn reserve ( & mut self , num_new_values : usize ) ;
@@ -66,20 +61,6 @@ impl<K: UnifyKey> Default for InPlace<K> {
66
61
}
67
62
}
68
63
69
- impl Measurable for sv:: Snapshot {
70
- #[ inline]
71
- fn len ( & self ) -> usize {
72
- self . length
73
- }
74
- }
75
-
76
- impl < K : UnifyKey > Measurable for InPlace < K > {
77
- #[ inline]
78
- fn len ( & self ) -> usize {
79
- self . values . len ( )
80
- }
81
- }
82
-
83
64
impl < K : UnifyKey > UnificationStore for InPlace < K > {
84
65
type Key = K ;
85
66
type Value = K :: Value ;
@@ -100,6 +81,11 @@ impl<K: UnifyKey> UnificationStore for InPlace<K> {
100
81
self . values . commit ( snapshot) ;
101
82
}
102
83
84
+ #[ inline]
85
+ fn values_since_snapshot ( & self , snapshot : & Self :: Snapshot ) -> Range < usize > {
86
+ snapshot. value_count ..self . len ( )
87
+ }
88
+
103
89
#[ inline]
104
90
fn reset_unifications (
105
91
& mut self ,
@@ -108,6 +94,10 @@ impl<K: UnifyKey> UnificationStore for InPlace<K> {
108
94
self . values . set_all ( |i| value ( i as u32 ) ) ;
109
95
}
110
96
97
+ fn len ( & self ) -> usize {
98
+ self . values . len ( )
99
+ }
100
+
111
101
#[ inline]
112
102
fn push ( & mut self , value : VarValue < Self :: Key > ) {
113
103
self . values . push ( value) ;
@@ -159,14 +149,6 @@ impl<K: UnifyKey> Default for Persistent<K> {
159
149
}
160
150
}
161
151
162
- #[ cfg( feature = "persistent" ) ]
163
- impl < K : UnifyKey > Measurable for Persistent < K > {
164
- #[ inline]
165
- fn len ( & self ) -> usize {
166
- self . values . len ( )
167
- }
168
- }
169
-
170
152
#[ cfg( feature = "persistent" ) ]
171
153
impl < K : UnifyKey > UnificationStore for Persistent < K > {
172
154
type Key = K ;
@@ -184,7 +166,11 @@ impl<K: UnifyKey> UnificationStore for Persistent<K> {
184
166
}
185
167
186
168
#[ inline]
187
- fn commit ( & mut self , _snapshot : Self :: Snapshot ) {
169
+ fn commit ( & mut self , _snapshot : Self :: Snapshot ) { }
170
+
171
+ #[ inline]
172
+ fn values_since_snapshot ( & self , snapshot : & Self :: Snapshot ) -> Range < usize > {
173
+ snapshot. len ( ) ..self . len ( )
188
174
}
189
175
190
176
#[ inline]
@@ -200,6 +186,10 @@ impl<K: UnifyKey> UnificationStore for Persistent<K> {
200
186
}
201
187
}
202
188
189
+ fn len ( & self ) -> usize {
190
+ self . values . len ( )
191
+ }
192
+
203
193
#[ inline]
204
194
fn push ( & mut self , value : VarValue < Self :: Key > ) {
205
195
self . values . push ( value) ;
0 commit comments