Skip to content
Merged
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 @@ -25,6 +25,7 @@ features = ["unstable_docrs"]
[features]
with_ahash = ["ahash"]
unstable_docrs = ["with_ahash"]
weak-table = ["dep:weak-table"]

[dependencies]
lazy_static = "1.*"
Expand All @@ -33,6 +34,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
33 changes: 33 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
/// - `$hash_builder:expr` optional hash builder, an
/// implementation of [`std::hash::BuildHasher`] ;
/// - `$typ:typ,` type being hashconsed (the underlying type, not the
/// hashconsed one) ;

Check warning on line 242 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

doc list item overindented

Check warning on line 242 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

doc list item overindented

Check warning on line 242 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

doc list item overindented
#[macro_export]
macro_rules! consign {
(
Expand Down Expand Up @@ -350,7 +350,7 @@
}
}
impl<T> Eq for HConsed<T> {}
impl<T> PartialOrd for HConsed<T> {

Check warning on line 353 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

non-canonical implementation of `partial_cmp` on an `Ord` type

Check warning on line 353 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

non-canonical implementation of `partial_cmp` on an `Ord` type

Check warning on line 353 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

non-canonical implementation of `partial_cmp` on an `Ord` type
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.uid.partial_cmp(&other.uid)
Expand Down Expand Up @@ -455,6 +455,39 @@
}
}

#[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