@@ -295,6 +295,12 @@ impl<S: UnificationStoreBase> UnificationTable<S> {
295
295
pub fn len ( & self ) -> usize {
296
296
self . values . len ( )
297
297
}
298
+
299
+ /// Obtains the current value for a particular key.
300
+ /// Not for end-users; they can use `probe_value`.
301
+ fn value ( & self , key : S :: Key ) -> & VarValue < S :: Key > {
302
+ & self . values [ key. index ( ) as usize ]
303
+ }
298
304
}
299
305
300
306
impl < S : UnificationStoreMut > UnificationTable < S > {
@@ -325,12 +331,6 @@ impl<S: UnificationStoreMut> UnificationTable<S> {
325
331
} ) ;
326
332
}
327
333
328
- /// Obtains the current value for a particular key.
329
- /// Not for end-users; they can use `probe_value`.
330
- fn value ( & self , key : S :: Key ) -> & VarValue < S :: Key > {
331
- & self . values [ key. index ( ) as usize ]
332
- }
333
-
334
334
/// Find the root node for `vid`. This uses the standard
335
335
/// union-find algorithm with path compression:
336
336
/// <http://en.wikipedia.org/wiki/Disjoint-set_data_structure>.
@@ -447,6 +447,28 @@ impl<S: UnificationStoreMut> UnificationTable<S> {
447
447
/// ////////////////////////////////////////////////////////////////////////
448
448
/// Public API
449
449
450
+ impl < S , K , V > UnificationTable < S >
451
+ where
452
+ S : UnificationStoreBase < Key = K , Value = V > ,
453
+ K : UnifyKey < Value = V > ,
454
+ V : UnifyValue ,
455
+ {
456
+ /// Obtains current value for key without any pointer chasing; may return `None` if key has been union'd.
457
+ #[ inline]
458
+ pub fn try_probe_value < ' a , K1 > ( & ' a self , id : K1 ) -> Option < & ' a V >
459
+ where
460
+ K1 : Into < K > ,
461
+ K : ' a ,
462
+ {
463
+ let id = id. into ( ) ;
464
+ let v = self . value ( id) ;
465
+ if v. parent == id {
466
+ return Some ( & v. value ) ;
467
+ }
468
+ None
469
+ }
470
+ }
471
+
450
472
impl < S , K , V > UnificationTable < S >
451
473
where
452
474
S : UnificationStoreMut < Key = K , Value = V > ,
0 commit comments