diff --git a/src/unify/mod.rs b/src/unify/mod.rs index defd7b7..604f3bd 100644 --- a/src/unify/mod.rs +++ b/src/unify/mod.rs @@ -295,6 +295,12 @@ impl UnificationTable { pub fn len(&self) -> usize { self.values.len() } + + /// Obtains the current value for a particular key. + /// Not for end-users; they can use `probe_value`. + fn value(&self, key: S::Key) -> &VarValue { + &self.values[key.index() as usize] + } } impl UnificationTable { @@ -325,12 +331,6 @@ impl UnificationTable { }); } - /// Obtains the current value for a particular key. - /// Not for end-users; they can use `probe_value`. - fn value(&self, key: S::Key) -> &VarValue { - &self.values[key.index() as usize] - } - /// Find the root node for `vid`. This uses the standard /// union-find algorithm with path compression: /// . @@ -447,6 +447,28 @@ impl UnificationTable { /// //////////////////////////////////////////////////////////////////////// /// Public API +impl UnificationTable +where + S: UnificationStoreBase, + K: UnifyKey, + V: UnifyValue, +{ + /// Obtains current value for key without any pointer chasing; may return `None` if key has been union'd. + #[inline] + pub fn try_probe_value<'a, K1>(&'a self, id: K1) -> Option<&'a V> + where + K1: Into, + K: 'a, + { + let id = id.into(); + let v = self.value(id); + if v.parent == id { + return Some(&v.value); + } + None + } +} + impl UnificationTable where S: UnificationStoreMut,