@@ -4,7 +4,7 @@ use snapshot_vec as sv;
44use std:: marker:: PhantomData ;
55use std:: ops:: { self , Range } ;
66
7- use undo_log:: { Rollback , Snapshots , VecLog } ;
7+ use undo_log:: { Rollback , Snapshots , UndoLogs , VecLog } ;
88
99use super :: { UnifyKey , UnifyValue , VarValue } ;
1010
@@ -26,9 +26,7 @@ pub trait UnificationStoreBase: ops::Index<usize, Output = VarValue<Key<Self>>>
2626 }
2727}
2828
29- pub trait UnificationStore : UnificationStoreBase {
30- type Snapshot ;
31-
29+ pub trait UnificationStoreMut : UnificationStoreBase {
3230 fn reset_unifications ( & mut self , value : impl FnMut ( u32 ) -> VarValue < Self :: Key > ) ;
3331
3432 fn push ( & mut self , value : VarValue < Self :: Key > ) ;
@@ -38,6 +36,10 @@ pub trait UnificationStore: UnificationStoreBase {
3836 fn update < F > ( & mut self , index : usize , op : F )
3937 where
4038 F : FnOnce ( & mut VarValue < Self :: Key > ) ;
39+ }
40+
41+ pub trait UnificationStore : UnificationStoreMut {
42+ type Snapshot ;
4143
4244 fn start_snapshot ( & mut self ) -> Self :: Snapshot ;
4345
@@ -81,14 +83,12 @@ where
8183 }
8284}
8385
84- impl < K , V , L > UnificationStore for InPlace < K , V , L >
86+ impl < K , V , L > UnificationStoreMut for InPlace < K , V , L >
8587where
8688 K : UnifyKey ,
8789 V : sv:: VecLike < Delegate < K > > ,
88- L : Snapshots < sv:: UndoLog < Delegate < K > > > ,
90+ L : UndoLogs < sv:: UndoLog < Delegate < K > > > ,
8991{
90- type Snapshot = sv:: Snapshot < L :: Snapshot > ;
91-
9292 #[ inline]
9393 fn reset_unifications ( & mut self , mut value : impl FnMut ( u32 ) -> VarValue < Self :: Key > ) {
9494 self . values . set_all ( |i| value ( i as u32 ) ) ;
@@ -111,6 +111,15 @@ where
111111 {
112112 self . values . update ( index, op)
113113 }
114+ }
115+
116+ impl < K , V , L > UnificationStore for InPlace < K , V , L >
117+ where
118+ K : UnifyKey ,
119+ V : sv:: VecLike < Delegate < K > > ,
120+ L : Snapshots < sv:: UndoLog < Delegate < K > > > ,
121+ {
122+ type Snapshot = sv:: Snapshot < L :: Snapshot > ;
114123
115124 #[ inline]
116125 fn start_snapshot ( & mut self ) -> Self :: Snapshot {
@@ -188,27 +197,7 @@ impl<K: UnifyKey> UnificationStoreBase for Persistent<K> {
188197}
189198
190199#[ cfg( feature = "persistent" ) ]
191- impl < K : UnifyKey > UnificationStore for Persistent < K > {
192- type Snapshot = Self ;
193-
194- #[ inline]
195- fn start_snapshot ( & mut self ) -> Self :: Snapshot {
196- self . clone ( )
197- }
198-
199- #[ inline]
200- fn rollback_to ( & mut self , snapshot : Self :: Snapshot ) {
201- * self = snapshot;
202- }
203-
204- #[ inline]
205- fn commit ( & mut self , _snapshot : Self :: Snapshot ) { }
206-
207- #[ inline]
208- fn values_since_snapshot ( & self , snapshot : & Self :: Snapshot ) -> Range < usize > {
209- snapshot. len ( ) ..self . len ( )
210- }
211-
200+ impl < K : UnifyKey > UnificationStoreMut for Persistent < K > {
212201 #[ inline]
213202 fn reset_unifications ( & mut self , mut value : impl FnMut ( u32 ) -> VarValue < Self :: Key > ) {
214203 // Without extending dogged, there isn't obviously a more
@@ -239,6 +228,29 @@ impl<K: UnifyKey> UnificationStore for Persistent<K> {
239228 }
240229}
241230
231+ #[ cfg( feature = "persistent" ) ]
232+ impl < K : UnifyKey > UnificationStore for Persistent < K > {
233+ type Snapshot = Self ;
234+
235+ #[ inline]
236+ fn start_snapshot ( & mut self ) -> Self :: Snapshot {
237+ self . clone ( )
238+ }
239+
240+ #[ inline]
241+ fn rollback_to ( & mut self , snapshot : Self :: Snapshot ) {
242+ * self = snapshot;
243+ }
244+
245+ #[ inline]
246+ fn commit ( & mut self , _snapshot : Self :: Snapshot ) { }
247+
248+ #[ inline]
249+ fn values_since_snapshot ( & self , snapshot : & Self :: Snapshot ) -> Range < usize > {
250+ snapshot. len ( ) ..self . len ( )
251+ }
252+ }
253+
242254#[ cfg( feature = "persistent" ) ]
243255impl < K > ops:: Index < usize > for Persistent < K >
244256where
0 commit comments