Skip to content

Commit 528af9a

Browse files
author
Markus Westerlind
committed
Don't require UndoLogs for calling len
1 parent 1f370f2 commit 528af9a

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

src/unify/backing_vec.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use snapshot_vec as sv;
44
use std::marker::PhantomData;
55
use std::ops::{self, Range};
66

7-
use undo_log::{Rollback, Snapshots, UndoLogs, VecLog};
7+
use undo_log::{Rollback, Snapshots, VecLog};
88

99
use super::{UnifyKey, UnifyValue, VarValue};
1010

@@ -19,18 +19,8 @@ pub trait UnificationStoreBase: ops::Index<usize, Output = VarValue<Key<Self>>>
1919
type Key: UnifyKey<Value = Self::Value>;
2020
type Value: UnifyValue;
2121

22-
fn reset_unifications(&mut self, value: impl FnMut(u32) -> VarValue<Self::Key>);
23-
2422
fn len(&self) -> usize;
2523

26-
fn push(&mut self, value: VarValue<Self::Key>);
27-
28-
fn reserve(&mut self, num_new_values: usize);
29-
30-
fn update<F>(&mut self, index: usize, op: F)
31-
where
32-
F: FnOnce(&mut VarValue<Self::Key>);
33-
3424
fn tag() -> &'static str {
3525
Self::Key::tag()
3626
}
@@ -39,6 +29,16 @@ pub trait UnificationStoreBase: ops::Index<usize, Output = VarValue<Key<Self>>>
3929
pub trait UnificationStore: UnificationStoreBase {
4030
type Snapshot;
4131

32+
fn reset_unifications(&mut self, value: impl FnMut(u32) -> VarValue<Self::Key>);
33+
34+
fn push(&mut self, value: VarValue<Self::Key>);
35+
36+
fn reserve(&mut self, num_new_values: usize);
37+
38+
fn update<F>(&mut self, index: usize, op: F)
39+
where
40+
F: FnOnce(&mut VarValue<Self::Key>);
41+
4242
fn start_snapshot(&mut self) -> Self::Snapshot;
4343

4444
fn rollback_to(&mut self, snapshot: Self::Snapshot);
@@ -72,20 +72,28 @@ impl<K, V, L> UnificationStoreBase for InPlace<K, V, L>
7272
where
7373
K: UnifyKey,
7474
V: sv::VecLike<Delegate<K>>,
75-
L: UndoLogs<sv::UndoLog<Delegate<K>>>,
7675
{
7776
type Key = K;
7877
type Value = K::Value;
7978

79+
fn len(&self) -> usize {
80+
self.values.len()
81+
}
82+
}
83+
84+
impl<K, V, L> UnificationStore for InPlace<K, V, L>
85+
where
86+
K: UnifyKey,
87+
V: sv::VecLike<Delegate<K>>,
88+
L: Snapshots<sv::UndoLog<Delegate<K>>>,
89+
{
90+
type Snapshot = sv::Snapshot<L::Snapshot>;
91+
8092
#[inline]
8193
fn reset_unifications(&mut self, mut value: impl FnMut(u32) -> VarValue<Self::Key>) {
8294
self.values.set_all(|i| value(i as u32));
8395
}
8496

85-
fn len(&self) -> usize {
86-
self.values.len()
87-
}
88-
8997
#[inline]
9098
fn push(&mut self, value: VarValue<Self::Key>) {
9199
self.values.push(value);
@@ -103,15 +111,6 @@ where
103111
{
104112
self.values.update(index, op)
105113
}
106-
}
107-
108-
impl<K, V, L> UnificationStore for InPlace<K, V, L>
109-
where
110-
K: UnifyKey,
111-
V: sv::VecLike<Delegate<K>>,
112-
L: Snapshots<sv::UndoLog<Delegate<K>>>,
113-
{
114-
type Snapshot = sv::Snapshot<L::Snapshot>;
115114

116115
#[inline]
117116
fn start_snapshot(&mut self) -> Self::Snapshot {

src/unify/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ impl<S: UnificationStore> UnificationTable<S> {
306306
}
307307

308308
impl<S: UnificationStoreBase> UnificationTable<S> {
309+
/// Returns the number of keys created so far.
310+
pub fn len(&self) -> usize {
311+
self.values.len()
312+
}
313+
}
314+
315+
impl<S: UnificationStore> UnificationTable<S> {
309316
/// Starts a new snapshot. Each snapshot must be either
310317
/// Creates a fresh key with the given value.
311318
pub fn new_key(&mut self, value: S::Value) -> S::Key {
@@ -333,11 +340,6 @@ impl<S: UnificationStoreBase> UnificationTable<S> {
333340
});
334341
}
335342

336-
/// Returns the number of keys created so far.
337-
pub fn len(&self) -> usize {
338-
self.values.len()
339-
}
340-
341343
/// Obtains the current value for a particular key.
342344
/// Not for end-users; they can use `probe_value`.
343345
fn value(&self, key: S::Key) -> &VarValue<S::Key> {
@@ -463,7 +465,7 @@ impl<S: UnificationStoreBase> UnificationTable<S> {
463465
464466
impl<S, K, V> UnificationTable<S>
465467
where
466-
S: UnificationStoreBase<Key = K, Value = V>,
468+
S: UnificationStore<Key = K, Value = V>,
467469
K: UnifyKey<Value = V>,
468470
V: UnifyValue,
469471
{

0 commit comments

Comments
 (0)