Skip to content

Commit c7e018c

Browse files
committed
some comments
1 parent 978127b commit c7e018c

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/unify/backing_vec.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ use super::{VarValue, UnifyKey, UnifyValue};
99
#[allow(dead_code)] // rustc BUG
1010
type Key<S> = <S as UnificationStore>::Key;
1111

12+
/// Largely internal trait implemented by the unification table
13+
/// backing store types. The most common such type is `InPlace`,
14+
/// which indicates a standard, mutable unification table.
1215
pub trait UnificationStore: ops::Index<usize, Output = VarValue<Key<Self>>> + Clone {
1316
type Key: UnifyKey<Value = Self::Value>;
1417
type Value: UnifyValue;
@@ -34,6 +37,8 @@ pub trait UnificationStore: ops::Index<usize, Output = VarValue<Key<Self>>> + Cl
3437
}
3538
}
3639

40+
/// Backing store for an in-place unification table.
41+
/// Not typically used directly.
3742
#[derive(Clone)]
3843
pub struct InPlace<K: UnifyKey> {
3944
values: sv::SnapshotVec<Delegate<K>>

src/unify/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
//! possible, use `NoError` (an uninstantiable struct). Using this
2828
//! type also unlocks various more ergonomic methods (e.g., `union()`
2929
//! in place of `unify_var_var()`).
30+
//!
31+
//! The best way to see how it is used is to read [the `tests.rs` file](tests.rs);
32+
//! search for e.g. `UnitKey`.
3033
3134
use std::marker;
3235
use std::fmt::Debug;
@@ -160,7 +163,19 @@ pub struct VarValue<K: UnifyKey> { // FIXME pub
160163
rank: u32, // max depth (only relevant to root)
161164
}
162165

163-
/// Table of unification keys and their values.
166+
/// Table of unification keys and their values. You must define a key type K
167+
/// that implements the `UnifyKey` trait. Unification tables can be used in two-modes:
168+
///
169+
/// - in-place (`UnificationTable<InPlace<K>>` or `InPlaceUnificationTable<K>`):
170+
/// - This is the standard mutable mode, where the array is modified
171+
/// in place.
172+
/// - To do backtracking, you can employ the `snapshot` and `rollback_to`
173+
/// methods.
174+
/// - persistent (`UnificationTable<Persistent<K>>` or `PersistentUnificationTable<K>`):
175+
/// - In this mode, we use a persistent vector to store the data, so that
176+
/// cloning the table is an O(1) operation.
177+
/// - This implies that ordinary operations are quite a bit slower though.
178+
/// - Requires the `persistent` feature be selected in your Cargo.toml file.
164179
#[derive(Clone)]
165180
pub struct UnificationTable<S: UnificationStore> {
166181
/// Indicates the current value of each key.

0 commit comments

Comments
 (0)