2
2
use dogged:: DVec ;
3
3
use snapshot_vec as sv;
4
4
use std:: ops;
5
+ use std:: ops:: RangeInclusive ;
5
6
use std:: marker:: PhantomData ;
6
7
7
8
use super :: { VarValue , UnifyKey , UnifyValue } ;
@@ -10,29 +11,35 @@ use super::{VarValue, UnifyKey, UnifyValue};
10
11
#[ allow( type_alias_bounds) ]
11
12
type Key < S : UnificationStore > = <S as UnificationStore >:: Key ;
12
13
14
+ pub trait Measurable {
15
+ fn len ( & self ) -> usize ;
16
+ }
17
+
13
18
/// Largely internal trait implemented by the unification table
14
19
/// backing store types. The most common such type is `InPlace`,
15
20
/// which indicates a standard, mutable unification table.
16
21
pub trait UnificationStore :
17
- ops:: Index < usize , Output = VarValue < Key < Self > > > + Clone + Default
22
+ ops:: Index < usize , Output = VarValue < Key < Self > > > + Measurable + Clone + Default
18
23
{
19
24
type Key : UnifyKey < Value = Self :: Value > ;
20
25
type Value : UnifyValue ;
21
- type Snapshot ;
26
+ type Snapshot : Measurable ;
22
27
23
28
fn start_snapshot ( & mut self ) -> Self :: Snapshot ;
24
29
25
30
fn rollback_to ( & mut self , snapshot : Self :: Snapshot ) ;
26
31
27
32
fn commit ( & mut self , snapshot : Self :: Snapshot ) ;
28
33
34
+ fn values_since_snapshot ( & mut self , snapshot : & Self :: Snapshot ) -> RangeInclusive < usize > {
35
+ snapshot. len ( ) ..=self . len ( )
36
+ }
37
+
29
38
fn reset_unifications (
30
39
& mut self ,
31
40
value : impl FnMut ( u32 ) -> VarValue < Self :: Key > ,
32
41
) ;
33
42
34
- fn len ( & self ) -> usize ;
35
-
36
43
fn push ( & mut self , value : VarValue < Self :: Key > ) ;
37
44
38
45
fn reserve ( & mut self , num_new_values : usize ) ;
@@ -59,6 +66,20 @@ impl<K: UnifyKey> Default for InPlace<K> {
59
66
}
60
67
}
61
68
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
+
62
83
impl < K : UnifyKey > UnificationStore for InPlace < K > {
63
84
type Key = K ;
64
85
type Value = K :: Value ;
@@ -87,11 +108,6 @@ impl<K: UnifyKey> UnificationStore for InPlace<K> {
87
108
self . values . set_all ( |i| value ( i as u32 ) ) ;
88
109
}
89
110
90
- #[ inline]
91
- fn len ( & self ) -> usize {
92
- self . values . len ( )
93
- }
94
-
95
111
#[ inline]
96
112
fn push ( & mut self , value : VarValue < Self :: Key > ) {
97
113
self . values . push ( value) ;
@@ -143,6 +159,14 @@ impl<K: UnifyKey> Default for Persistent<K> {
143
159
}
144
160
}
145
161
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
+
146
170
#[ cfg( feature = "persistent" ) ]
147
171
impl < K : UnifyKey > UnificationStore for Persistent < K > {
148
172
type Key = K ;
@@ -176,11 +200,6 @@ impl<K: UnifyKey> UnificationStore for Persistent<K> {
176
200
}
177
201
}
178
202
179
- #[ inline]
180
- fn len ( & self ) -> usize {
181
- self . values . len ( )
182
- }
183
-
184
203
#[ inline]
185
204
fn push ( & mut self , value : VarValue < Self :: Key > ) {
186
205
self . values . push ( value) ;
0 commit comments