From a7b40f0519ad3276a7c035b96aa95d3cbe0213fb Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 14 Mar 2019 13:35:09 +0000 Subject: [PATCH 1/2] Make sv::Snapshot length pub(crate) --- src/snapshot_vec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/snapshot_vec.rs b/src/snapshot_vec.rs index 4c1c261..ed02ee4 100644 --- a/src/snapshot_vec.rs +++ b/src/snapshot_vec.rs @@ -61,7 +61,7 @@ impl fmt::Debug for SnapshotVec // Snapshots are tokens that should be created/consumed linearly. pub struct Snapshot { // Length of the undo log at the time the snapshot was taken. - length: usize, + pub(crate) length: usize, } pub trait SnapshotVecDelegate { From bdbaa65995b844baf2945b6bc569ff9caf615d78 Mon Sep 17 00:00:00 2001 From: varkor Date: Thu, 14 Mar 2019 12:29:03 +0000 Subject: [PATCH 2/2] Add values_since_snapshot --- src/unify/backing_vec.rs | 47 ++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/unify/backing_vec.rs b/src/unify/backing_vec.rs index f1e720c..e3e91ca 100644 --- a/src/unify/backing_vec.rs +++ b/src/unify/backing_vec.rs @@ -2,6 +2,7 @@ use dogged::DVec; use snapshot_vec as sv; use std::ops; +use std::ops::RangeInclusive; use std::marker::PhantomData; use super::{VarValue, UnifyKey, UnifyValue}; @@ -10,15 +11,19 @@ use super::{VarValue, UnifyKey, UnifyValue}; #[allow(type_alias_bounds)] type Key = ::Key; +pub trait Measurable { + fn len(&self) -> usize; +} + /// Largely internal trait implemented by the unification table /// backing store types. The most common such type is `InPlace`, /// which indicates a standard, mutable unification table. pub trait UnificationStore: - ops::Index>> + Clone + Default + ops::Index>> + Measurable + Clone + Default { type Key: UnifyKey; type Value: UnifyValue; - type Snapshot; + type Snapshot: Measurable; fn start_snapshot(&mut self) -> Self::Snapshot; @@ -26,13 +31,15 @@ pub trait UnificationStore: fn commit(&mut self, snapshot: Self::Snapshot); + fn values_since_snapshot(&mut self, snapshot: &Self::Snapshot) -> RangeInclusive { + snapshot.len()..=self.len() + } + fn reset_unifications( &mut self, value: impl FnMut(u32) -> VarValue, ); - fn len(&self) -> usize; - fn push(&mut self, value: VarValue); fn reserve(&mut self, num_new_values: usize); @@ -59,6 +66,20 @@ impl Default for InPlace { } } +impl Measurable for sv::Snapshot { + #[inline] + fn len(&self) -> usize { + self.length + } +} + +impl Measurable for InPlace { + #[inline] + fn len(&self) -> usize { + self.values.len() + } +} + impl UnificationStore for InPlace { type Key = K; type Value = K::Value; @@ -87,11 +108,6 @@ impl UnificationStore for InPlace { self.values.set_all(|i| value(i as u32)); } - #[inline] - fn len(&self) -> usize { - self.values.len() - } - #[inline] fn push(&mut self, value: VarValue) { self.values.push(value); @@ -143,6 +159,14 @@ impl Default for Persistent { } } +#[cfg(feature = "persistent")] +impl Measurable for Persistent { + #[inline] + fn len(&self) -> usize { + self.values.len() + } +} + #[cfg(feature = "persistent")] impl UnificationStore for Persistent { type Key = K; @@ -176,11 +200,6 @@ impl UnificationStore for Persistent { } } - #[inline] - fn len(&self) -> usize { - self.values.len() - } - #[inline] fn push(&mut self, value: VarValue) { self.values.push(value);