@@ -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,31 @@ 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
+ /// Attempts to return the current value for the given key. If the key has
457
+ /// been union'd, this may give the current value from the current root or `None`.
458
+ ///
459
+ /// This is useful for fast-paths that want to avoid pointer-chasing.
460
+ #[ inline]
461
+ pub fn try_probe_value < ' a , K1 > ( & ' a self , id : K1 ) -> Option < & ' a V >
462
+ where
463
+ K1 : Into < K > ,
464
+ K : ' a ,
465
+ {
466
+ let id = id. into ( ) ;
467
+ let v = self . value ( id) ;
468
+ if v. parent == id {
469
+ return Some ( & v. value ) ;
470
+ }
471
+ None
472
+ }
473
+ }
474
+
450
475
impl < S , K , V > UnificationTable < S >
451
476
where
452
477
S : UnificationStoreMut < Key = K , Value = V > ,
0 commit comments