Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
*.lock

# Ignore target directory.
/target
**/target

# Ignore crappy mac files.
.DS_Store
Expand Down
42 changes: 5 additions & 37 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,39 +1,7 @@
[package]
name = "hashconsing"
version = "1.6.0"
authors = ["Adrien Champion <adrien.champion@email.com>"]
description = "A hash consing library."
documentation = "https://docs.rs/hashconsing"
homepage = "https://github.com/AdrienChampion/hashconsing"
repository = "https://github.com/AdrienChampion/hashconsing"
readme = "README.md"
categories = [
"caching",
"compression",
"concurrency",
"data-structures",
"memory-management",
[workspace]
members = [
"hashconsing",
"hashconsing_derive",
]
keywords = ["hashconsing", "hash", "consing", "sharing", "caching"]
license = "MIT/Apache-2.0"
edition = "2021"

[package.metadata.docs.rs]
features = ["unstable_docrs"]

[features]
with_ahash = ["ahash"]
unstable_docrs = ["with_ahash"]

[dependencies]
lazy_static = "1.*"

[dependencies.ahash]
version = "^0.8.3"
optional = true

[dev-dependencies]
crossbeam-utils = "^0.8"
trybuild = "^1.0"
rayon = "^1.5"
rand = "0.8"
resolver = "2"
41 changes: 41 additions & 0 deletions hashconsing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "hashconsing"
version = "1.6.0"
authors = ["Adrien Champion <adrien.champion@email.com>"]
description = "A hash consing library."
documentation = "https://docs.rs/hashconsing"
homepage = "https://github.com/AdrienChampion/hashconsing"
repository = "https://github.com/AdrienChampion/hashconsing"
readme = "README.md"
categories = [
"caching",
"compression",
"concurrency",
"data-structures",
"memory-management",
]
keywords = ["hashconsing", "hash", "consing", "sharing", "caching"]
license = "MIT/Apache-2.0"
edition = "2021"

[package.metadata.docs.rs]
features = ["unstable_docrs"]

[features]
with_ahash = ["ahash"]
unstable_docrs = ["with_ahash"]
derive = ["hashconsing-derive"]

[dependencies]
lazy_static = "1.*"
hashconsing-derive = { version = "0.1.0", optional = true, path = "../hashconsing_derive" }

[dependencies.ahash]
version = "^0.8.3"
optional = true

[dev-dependencies]
crossbeam-utils = "=0.8.15"
trybuild = "^1.0"
rayon = "^1.5"
rand = "0.8"
12 changes: 6 additions & 6 deletions src/coll.rs → hashconsing/src/coll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ where
}
/// An iterator visiting all elements.
#[inline]
pub fn iter(&self) -> ::std::collections::hash_set::Iter<HConsed<T::Inner>> {
pub fn iter(&self) -> ::std::collections::hash_set::Iter<'_, HConsed<T::Inner>> {
self.set.iter()
}
}
Expand Down Expand Up @@ -322,12 +322,12 @@ where
}
/// An iterator visiting all elements.
#[inline]
pub fn iter(&self) -> ::std::collections::hash_map::Iter<HConsed<T::Inner>, V> {
pub fn iter(&self) -> ::std::collections::hash_map::Iter<'_, HConsed<T::Inner>, V> {
self.map.iter()
}
/// An iterator visiting all elements.
#[inline]
pub fn iter_mut(&mut self) -> ::std::collections::hash_map::IterMut<HConsed<T::Inner>, V> {
pub fn iter_mut(&mut self) -> ::std::collections::hash_map::IterMut<'_, HConsed<T::Inner>, V> {
self.map.iter_mut()
}
}
Expand Down Expand Up @@ -437,7 +437,7 @@ mod hash {
impl HashU64 {
/// Checks that a slice of bytes has the length of a `usize`. Only active
/// in debug.
#[cfg(debug)]
#[cfg(debug_assertions)]
#[inline(always)]
fn test_bytes(bytes: &[u8]) {
if bytes.len() != 8 {
Expand All @@ -451,13 +451,13 @@ mod hash {
}
/// Checks that a slice of bytes has the length of a `usize`. Only active
/// in debug.
#[cfg(not(debug))]
#[cfg(not(debug_assertions))]
#[inline(always)]
fn test_bytes(_: &[u8]) {}
}
impl Hasher for HashU64 {
fn finish(&self) -> u64 {
unsafe { ::std::mem::transmute(self.buf) }
u64::from_ne_bytes(self.buf)
}
fn write(&mut self, bytes: &[u8]) {
Self::test_bytes(bytes);
Expand Down
18 changes: 9 additions & 9 deletions src/hash_coll.rs → hashconsing/src/hash_coll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@
//! be the natural one, *e.g.* `HConSet<Term>`.
//!
//! However, since `Term` is really an alias for `HConsed<RTerm>`, then if we wanted to declare
//! `HConSet` as an alias for `HashSet` we would get `type HConSet<Inner> = HashSet< HConsed<Inner>
//! >` (omitting the custom hasher). That is, our sets would have type `HConSet<RTerm>`, which is
//! not very pretty. We could just define an alias though: `type TermSet = HConSet<RTerm>`, but it
//! `HConSet` as an alias for `HashSet` we would get `type ``HConSet<Inner>`` = HashSet< ``HConsed<Inner>``
//! >` (omitting the custom hasher). That is, our sets would have type ``HConSet<RTerm>``, which is
//! not very pretty. We could just define an alias though: `type TermSet = `HConSet<RTerm>``, but it
//! turns out it's better to wrap the actual set in a `struct` anyway. Mostly to be able to define
//! `new` and `with_capacity` without relying on a trait (users would need to import) to do that.
//!
Expand Down Expand Up @@ -322,7 +322,7 @@ where
{
/// An iterator visiting all elements.
#[inline]
pub fn iter(&self) -> ::std::collections::hash_set::Iter<HConsed<T::Inner>> {
pub fn iter(&self) -> ::std::collections::hash_set::Iter<'_, HConsed<T::Inner>> {
self.set.iter()
}
}
Expand Down Expand Up @@ -520,12 +520,12 @@ where
{
/// An iterator visiting all elements.
#[inline]
pub fn iter(&self) -> ::std::collections::hash_map::Iter<HConsed<T::Inner>, V> {
pub fn iter(&self) -> ::std::collections::hash_map::Iter<'_, HConsed<T::Inner>, V> {
self.map.iter()
}
/// An iterator visiting all elements.
#[inline]
pub fn iter_mut(&mut self) -> ::std::collections::hash_map::IterMut<HConsed<T::Inner>, V> {
pub fn iter_mut(&mut self) -> ::std::collections::hash_map::IterMut<'_, HConsed<T::Inner>, V> {
self.map.iter_mut()
}
}
Expand Down Expand Up @@ -643,7 +643,7 @@ mod hash {
impl HashU64 {
/// Checks that a slice of bytes has the length of a `usize`. Only active
/// in debug.
#[cfg(debug)]
#[cfg(debug_assertions)]
#[inline(always)]
fn test_bytes(bytes: &[u8]) {
if bytes.len() != 8 {
Expand All @@ -657,13 +657,13 @@ mod hash {
}
/// Checks that a slice of bytes has the length of a `usize`. Only active
/// in debug.
#[cfg(not(debug))]
#[cfg(not(debug_assertions))]
#[inline(always)]
fn test_bytes(_: &[u8]) {}
}
impl Hasher for HashU64 {
fn finish(&self) -> u64 {
let block: u64 = unsafe { ::std::mem::transmute(self.buf) };
let block: u64 = u64::from_ne_bytes(self.buf);
// Multiply by random 64-bit prime to distribute
block.wrapping_mul(0xDA5DF7A7BD02F2C7u64)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub mod p_hash {
impl Hasher {
/// Checks that a slice of bytes has the length of a `usize`. Only active
/// in debug.
#[cfg(debug)]
#[cfg(debug_assertions)]
#[inline(always)]
fn test_bytes(bytes: &[u8]) {
if bytes.len() != 8 {
Expand All @@ -64,13 +64,13 @@ pub mod p_hash {
}
/// Checks that a slice of bytes has the length of a `usize`. Only active
/// in debug.
#[cfg(not(debug))]
#[cfg(not(debug_assertions))]
#[inline(always)]
fn test_bytes(_: &[u8]) {}
}
impl StdHasherExt for Hasher {
fn finish(&self) -> u64 {
let block: u64 = unsafe { ::std::mem::transmute(self.buf) };
let block: u64 = u64::from_ne_bytes(self.buf);
// Multiply by random 64-bit prime to distribute
block.wrapping_mul(0xDA5DF7A7BD02F2C7u64)
}
Expand Down Expand Up @@ -112,7 +112,7 @@ pub mod id_hash {
impl Hasher {
/// Checks that a slice of bytes has the length of a `usize`. Only active
/// in debug.
#[cfg(debug)]
#[cfg(debug_assertions)]
#[inline(always)]
fn test_bytes(bytes: &[u8]) {
if bytes.len() != 8 {
Expand All @@ -126,13 +126,13 @@ pub mod id_hash {
}
/// Checks that a slice of bytes has the length of a `usize`. Only active
/// in debug.
#[cfg(not(debug))]
#[cfg(not(debug_assertions))]
#[inline(always)]
fn test_bytes(_: &[u8]) {}
}
impl StdHasherExt for Hasher {
fn finish(&self) -> u64 {
unsafe { ::std::mem::transmute(self.buf) }
u64::from_ne_bytes(self.buf)
}
fn write(&mut self, bytes: &[u8]) {
Self::test_bytes(bytes);
Expand Down
19 changes: 13 additions & 6 deletions src/lib.rs → hashconsing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,14 @@ use std::{

pub extern crate lazy_static;

#[cfg(feature = "derive")]
#[allow(unused_imports)]
#[macro_use]
extern crate hashconsing_derive;
#[cfg(feature = "derive")]
#[doc(hidden)]
pub use hashconsing_derive::*;

#[cfg(test)]
mod test;

Expand All @@ -239,8 +247,7 @@ mod test;
/// - `$capa:expr` initial capacity when creating the consign ;
/// - `$hash_builder:expr` optional hash builder, an
/// implementation of [`std::hash::BuildHasher`] ;
/// - `$typ:typ,` type being hashconsed (the underlying type, not the
/// hashconsed one) ;
/// - `$typ:typ,` type being hashconsed (the underlying type, not the hashconsed one) ;
#[macro_export]
macro_rules! consign {
(
Expand Down Expand Up @@ -354,7 +361,7 @@ impl<T> Eq for HConsed<T> {}
impl<T> PartialOrd for HConsed<T> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.uid.partial_cmp(&other.uid)
Some(self.cmp(other))
}
}
impl<T> Ord for HConsed<T> {
Expand Down Expand Up @@ -441,7 +448,7 @@ impl<T> Eq for WHConsed<T> {}
impl<T> PartialOrd for WHConsed<T> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.uid.partial_cmp(&other.uid)
Some(self.cmp(other))
}
}
impl<T> Ord for WHConsed<T> {
Expand Down Expand Up @@ -620,7 +627,7 @@ pub trait HashConsign<T: Hash>: Sized {
/// Reserves capacity for at least `additional` more elements.
fn reserve(self, additional: usize);
}
impl<'a, T: Hash + Eq + Clone, S: BuildHasher> HashConsign<T> for &'a mut HConsign<T, S> {
impl<T: Hash + Eq + Clone, S: BuildHasher> HashConsign<T> for &mut HConsign<T, S> {
fn mk_is_new(self, elm: T) -> (HConsed<T>, bool) {
// If the element is known and upgradable return it.
if let Some(hconsed) = self.get(&elm) {
Expand Down Expand Up @@ -693,7 +700,7 @@ macro_rules! get {
};
}

impl<'a, T: Hash + Eq + Clone> HashConsign<T> for &'a RwLock<HConsign<T>> {
impl<T: Hash + Eq + Clone> HashConsign<T> for &RwLock<HConsign<T>> {
/// If the element is already in the consign, only read access will be
/// requested.
fn mk_is_new(self, elm: T) -> (HConsed<T>, bool) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ error[E0277]: `Cell<RefOrInt<'_>>` cannot be shared between threads safely
39 | |
40 | | loop {
... |
44 | | }
45 | | });
| |_________^ `Cell<RefOrInt<'_>>` cannot be shared between threads safely
|
Expand All @@ -33,7 +32,7 @@ note: required because it's used within this closure
37 | s.spawn(move |_| {
| ^^^^^^^^
note: required by a bound in `crossbeam_utils::thread::Scope::<'env>::spawn`
--> $CARGO/crossbeam-utils-0.8.16/src/thread.rs
--> $CARGO/crossbeam-utils-$VERSION/src/thread.rs
|
| pub fn spawn<'scope, F, T>(&'scope self, f: F) -> ScopedJoinHandle<'scope, T>
| ----- required by a bound in this associated function
Expand Down
20 changes: 20 additions & 0 deletions hashconsing_derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "hashconsing-derive"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
proc-macro = true

[dependencies]
darling = "0.20"
proc-macro-error = "1.0"
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "2.0", features = ["full"] }

# For doc tests
[dev-dependencies]
hashconsing = {path = "../hashconsing", features = ["derive"]}
Loading