Skip to content

Commit e402f6a

Browse files
committed
make it possible to clone a UnificationTable
1 parent 1dac7f9 commit e402f6a

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

src/snapshot_vec.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,29 @@ impl<D: SnapshotVecDelegate> ops::IndexMut<usize> for SnapshotVec<D> {
223223
self.get_mut(index)
224224
}
225225
}
226+
227+
impl<D: SnapshotVecDelegate> Clone for SnapshotVec<D>
228+
where D::Value: Clone, D::Undo: Clone,
229+
{
230+
fn clone(&self) -> Self {
231+
SnapshotVec {
232+
values: self.values.clone(),
233+
undo_log: self.undo_log.clone(),
234+
}
235+
}
236+
}
237+
238+
impl<D: SnapshotVecDelegate> Clone for UndoLog<D>
239+
where D::Value: Clone, D::Undo: Clone,
240+
{
241+
fn clone(&self) -> Self {
242+
match *self {
243+
OpenSnapshot => OpenSnapshot,
244+
CommittedSnapshot => CommittedSnapshot,
245+
NewElem(i) => NewElem(i),
246+
SetElem(i, ref v) => SetElem(i, v.clone()),
247+
Other(ref u) => Other(u.clone()),
248+
}
249+
}
250+
}
251+

src/unify/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct VarValue<K: UnifyKey> {
8585
}
8686

8787
/// Table of unification keys and their values.
88+
#[derive(Clone)]
8889
pub struct UnificationTable<K: UnifyKey> {
8990
/// Indicates the current value of each key.
9091
values: sv::SnapshotVec<Delegate<K>>,

src/unify/tests.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,3 +317,17 @@ fn ordered_key_k1() {
317317
assert!(vec![k1_5, k1_6].contains(&ut.find(k0_1)),
318318
"unexpected choice for root: {:?}", ut.find(k0_1));
319319
}
320+
321+
/// Test that we *can* clone.
322+
#[test]
323+
fn clone_table() {
324+
let mut ut: UnificationTable<IntKey> = UnificationTable::new();
325+
let k1 = ut.new_key(None);
326+
let k2 = ut.new_key(None);
327+
assert!(ut.unify_var_value(k1, Some(22)).is_ok());
328+
assert!(ut.unify_var_value(k2, Some(22)).is_ok());
329+
assert!(ut.unify_var_var(k1, k2).is_ok());
330+
331+
let mut ut1 = ut.clone();
332+
assert_eq!(ut1.probe_value(k1), Some(22));
333+
}

0 commit comments

Comments
 (0)