File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ features = ["unstable_docrs"]
2525[features ]
2626with_ahash = [" ahash" ]
2727unstable_docrs = [" with_ahash" ]
28+ weak-table = [" dep:weak-table" ]
2829
2930[dependencies ]
3031lazy_static = " 1.*"
@@ -33,6 +34,10 @@ lazy_static = "1.*"
3334version = " ^0.8.3"
3435optional = true
3536
37+ [dependencies .weak-table ]
38+ version = " ^0.3.0"
39+ optional = true
40+
3641[dev-dependencies ]
3742crossbeam-utils = " ^0.8"
3843trybuild = " ^1.0"
Original file line number Diff line number Diff line change @@ -455,6 +455,39 @@ impl<T> Ord for WHConsed<T> {
455455 }
456456}
457457
458+ #[ cfg( feature = "weak-table" ) ]
459+ use weak_table:: traits:: { WeakElement , WeakKey } ;
460+
461+ #[ cfg( feature = "weak-table" ) ]
462+ impl < T > WeakElement for WHConsed < T > {
463+ type Strong = HConsed < T > ;
464+ fn new ( x : & Self :: Strong ) -> Self {
465+ x. to_weak ( )
466+ }
467+ fn view ( & self ) -> Option < Self :: Strong > {
468+ self . to_hconsed ( )
469+ }
470+ fn is_expired ( & self ) -> bool {
471+ self . elm . is_expired ( )
472+ }
473+ fn clone ( x : & Self :: Strong ) -> Self :: Strong
474+ where
475+ Self : Sized ,
476+ {
477+ x. clone ( )
478+ }
479+ }
480+ #[ cfg( feature = "weak-table" ) ]
481+ impl < T : std:: hash:: Hash + Eq > WeakKey for WHConsed < T > {
482+ type Key = T ;
483+ fn with_key < F , R > ( view : & Self :: Strong , f : F ) -> R
484+ where
485+ F : FnOnce ( & Self :: Key ) -> R ,
486+ {
487+ f ( view)
488+ }
489+ }
490+
458491/// The consign storing the actual hash consed elements as `HConsed`s.
459492pub struct HConsign < T : Hash + Eq + Clone , S = RandomState > {
460493 /// The actual hash consing table.
You can’t perform that action at this time.
0 commit comments