Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ features = ["unstable_docrs"]
[features]
with_ahash = ["ahash"]
unstable_docrs = ["with_ahash"]
weak-table = ["dep:weak-table"]

[dependencies]
lazy_static = "1.*"
Expand All @@ -32,6 +33,10 @@ lazy_static = "1.*"
version = "^0.8.3"
optional = true

[dependencies.weak-table]
version = "^0.3.0"
optional = true

[dev-dependencies]
crossbeam-utils = "^0.8"
trybuild = "^1.0"
Expand Down
37 changes: 37 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,43 @@ impl<T> Ord for WHConsed<T> {
}
}

#[cfg(feature = "weak-table")]
use weak_table::traits::{WeakElement, WeakKey};

#[cfg(feature = "weak-table")]
impl<T> WeakElement for WHConsed<T> {
type Strong = HConsed<T>;
fn new(x: &Self::Strong) -> Self
{
x.to_weak()
}
fn view(&self) -> Option<Self::Strong>
{
self.to_hconsed()
}
fn is_expired(&self) -> bool
{
self.elm.is_expired()
}
fn clone(x: &Self::Strong) -> Self::Strong
where
Self: Sized,
{
x.clone()
}
}
#[cfg(feature = "weak-table")]
impl<T: std::hash::Hash + Eq> WeakKey for WHConsed<T> {
type Key = T;
fn with_key<F, R>(view: &Self::Strong, f: F) -> R
where
F: FnOnce(&Self::Key) -> R,
{
f(view)
}
}


/// The consign storing the actual hash consed elements as `HConsed`s.
pub struct HConsign<T: Hash + Eq + Clone, S = RandomState> {
/// The actual hash consing table.
Expand Down
Loading