22use dogged:: DVec ;
33use snapshot_vec as sv;
44use std:: ops;
5+ use std:: ops:: RangeInclusive ;
56use std:: marker:: PhantomData ;
67
78use super :: { VarValue , UnifyKey , UnifyValue } ;
@@ -10,29 +11,35 @@ use super::{VarValue, UnifyKey, UnifyValue};
1011#[ allow( type_alias_bounds) ]
1112type Key < S : UnificationStore > = <S as UnificationStore >:: Key ;
1213
14+ pub trait Measurable {
15+ fn len ( & self ) -> usize ;
16+ }
17+
1318/// Largely internal trait implemented by the unification table
1419/// backing store types. The most common such type is `InPlace`,
1520/// which indicates a standard, mutable unification table.
1621pub trait UnificationStore :
17- ops:: Index < usize , Output = VarValue < Key < Self > > > + Clone + Default
22+ ops:: Index < usize , Output = VarValue < Key < Self > > > + Measurable + Clone + Default
1823{
1924 type Key : UnifyKey < Value = Self :: Value > ;
2025 type Value : UnifyValue ;
21- type Snapshot ;
26+ type Snapshot : Measurable ;
2227
2328 fn start_snapshot ( & mut self ) -> Self :: Snapshot ;
2429
2530 fn rollback_to ( & mut self , snapshot : Self :: Snapshot ) ;
2631
2732 fn commit ( & mut self , snapshot : Self :: Snapshot ) ;
2833
34+ fn values_since_snapshot ( & mut self , snapshot : & Self :: Snapshot ) -> RangeInclusive < usize > {
35+ snapshot. len ( ) ..=self . len ( )
36+ }
37+
2938 fn reset_unifications (
3039 & mut self ,
3140 value : impl FnMut ( u32 ) -> VarValue < Self :: Key > ,
3241 ) ;
3342
34- fn len ( & self ) -> usize ;
35-
3643 fn push ( & mut self , value : VarValue < Self :: Key > ) ;
3744
3845 fn reserve ( & mut self , num_new_values : usize ) ;
@@ -59,6 +66,20 @@ impl<K: UnifyKey> Default for InPlace<K> {
5966 }
6067}
6168
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+
6283impl < K : UnifyKey > UnificationStore for InPlace < K > {
6384 type Key = K ;
6485 type Value = K :: Value ;
@@ -87,11 +108,6 @@ impl<K: UnifyKey> UnificationStore for InPlace<K> {
87108 self . values . set_all ( |i| value ( i as u32 ) ) ;
88109 }
89110
90- #[ inline]
91- fn len ( & self ) -> usize {
92- self . values . len ( )
93- }
94-
95111 #[ inline]
96112 fn push ( & mut self , value : VarValue < Self :: Key > ) {
97113 self . values . push ( value) ;
@@ -143,6 +159,14 @@ impl<K: UnifyKey> Default for Persistent<K> {
143159 }
144160}
145161
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+
146170#[ cfg( feature = "persistent" ) ]
147171impl < K : UnifyKey > UnificationStore for Persistent < K > {
148172 type Key = K ;
@@ -176,11 +200,6 @@ impl<K: UnifyKey> UnificationStore for Persistent<K> {
176200 }
177201 }
178202
179- #[ inline]
180- fn len ( & self ) -> usize {
181- self . values . len ( )
182- }
183-
184203 #[ inline]
185204 fn push ( & mut self , value : VarValue < Self :: Key > ) {
186205 self . values . push ( value) ;
0 commit comments