11#[ cfg( feature = "persistent" ) ]
22use dogged:: DVec ;
33use snapshot_vec as sv;
4- use std:: ops;
5- use std:: ops:: RangeInclusive ;
4+ use std:: ops:: { self , Range } ;
65use std:: marker:: PhantomData ;
76
87use super :: { VarValue , UnifyKey , UnifyValue } ;
@@ -11,35 +10,31 @@ use super::{VarValue, UnifyKey, UnifyValue};
1110#[ allow( type_alias_bounds) ]
1211type Key < S : UnificationStore > = <S as UnificationStore >:: Key ;
1312
14- pub trait Measurable {
15- fn len ( & self ) -> usize ;
16- }
17-
1813/// Largely internal trait implemented by the unification table
1914/// backing store types. The most common such type is `InPlace`,
2015/// which indicates a standard, mutable unification table.
2116pub trait UnificationStore :
22- ops:: Index < usize , Output = VarValue < Key < Self > > > + Measurable + Clone + Default
17+ ops:: Index < usize , Output = VarValue < Key < Self > > > + Clone + Default
2318{
2419 type Key : UnifyKey < Value = Self :: Value > ;
2520 type Value : UnifyValue ;
26- type Snapshot : Measurable ;
21+ type Snapshot ;
2722
2823 fn start_snapshot ( & mut self ) -> Self :: Snapshot ;
2924
3025 fn rollback_to ( & mut self , snapshot : Self :: Snapshot ) ;
3126
3227 fn commit ( & mut self , snapshot : Self :: Snapshot ) ;
3328
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 > ;
3730
3831 fn reset_unifications (
3932 & mut self ,
4033 value : impl FnMut ( u32 ) -> VarValue < Self :: Key > ,
4134 ) ;
4235
36+ fn len ( & self ) -> usize ;
37+
4338 fn push ( & mut self , value : VarValue < Self :: Key > ) ;
4439
4540 fn reserve ( & mut self , num_new_values : usize ) ;
@@ -66,20 +61,6 @@ impl<K: UnifyKey> Default for InPlace<K> {
6661 }
6762}
6863
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-
8364impl < K : UnifyKey > UnificationStore for InPlace < K > {
8465 type Key = K ;
8566 type Value = K :: Value ;
@@ -100,6 +81,11 @@ impl<K: UnifyKey> UnificationStore for InPlace<K> {
10081 self . values . commit ( snapshot) ;
10182 }
10283
84+ #[ inline]
85+ fn values_since_snapshot ( & self , snapshot : & Self :: Snapshot ) -> Range < usize > {
86+ snapshot. value_count ..self . len ( )
87+ }
88+
10389 #[ inline]
10490 fn reset_unifications (
10591 & mut self ,
@@ -108,6 +94,10 @@ impl<K: UnifyKey> UnificationStore for InPlace<K> {
10894 self . values . set_all ( |i| value ( i as u32 ) ) ;
10995 }
11096
97+ fn len ( & self ) -> usize {
98+ self . values . len ( )
99+ }
100+
111101 #[ inline]
112102 fn push ( & mut self , value : VarValue < Self :: Key > ) {
113103 self . values . push ( value) ;
@@ -159,14 +149,6 @@ impl<K: UnifyKey> Default for Persistent<K> {
159149 }
160150}
161151
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-
170152#[ cfg( feature = "persistent" ) ]
171153impl < K : UnifyKey > UnificationStore for Persistent < K > {
172154 type Key = K ;
@@ -184,7 +166,11 @@ impl<K: UnifyKey> UnificationStore for Persistent<K> {
184166 }
185167
186168 #[ 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 ( )
188174 }
189175
190176 #[ inline]
@@ -200,6 +186,10 @@ impl<K: UnifyKey> UnificationStore for Persistent<K> {
200186 }
201187 }
202188
189+ fn len ( & self ) -> usize {
190+ self . values . len ( )
191+ }
192+
203193 #[ inline]
204194 fn push ( & mut self , value : VarValue < Self :: Key > ) {
205195 self . values . push ( value) ;
0 commit comments