Skip to content

Commit 48fc421

Browse files
authored
Merge pull request #29 from AdrienChampion/prepare_1.7.0
chore: version bump 1.7.0, update authors/contributors, fix warnings, restore `deny(warnings)`
2 parents 1cac855 + f943da4 commit 48fc421

6 files changed

Lines changed: 50 additions & 41 deletions

File tree

Cargo.toml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
[package]
22
name = "hashconsing"
3-
version = "1.6.0"
4-
authors = ["Adrien Champion <adrien.champion@email.com>"]
3+
version = "1.7.0"
4+
authors = [
5+
"Adrien Champion <adrien.champion@email.com>",
6+
"Leni Aniva <aniva@stanford.edu>",
7+
]
58
description = "A hash consing library."
69
documentation = "https://docs.rs/hashconsing"
710
homepage = "https://github.com/AdrienChampion/hashconsing"
811
repository = "https://github.com/AdrienChampion/hashconsing"
912
readme = "README.md"
1013
categories = [
11-
"caching",
12-
"compression",
13-
"concurrency",
14-
"data-structures",
15-
"memory-management",
14+
"caching",
15+
"compression",
16+
"concurrency",
17+
"data-structures",
18+
"memory-management",
1619
]
1720
keywords = ["hashconsing", "hash", "consing", "sharing", "caching"]
1821
license = "MIT/Apache-2.0"

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ efficient as uses Rust's `HashMap`s, not a custom built structure.
1212

1313
For more details see [the documentation][doc].
1414

15-
# Known projects using `hashconsing`
16-
17-
- [kinō][kino], a model-checker for transition systems
18-
- [hoice][hoice], a machine-learning-based predicate synthesizer for horn clauses
19-
2015
# License
2116

2217
MIT/Apache-2.0
2318

24-
# Contributors
19+
# Developers
20+
21+
- [@adrienchampion](https://github.com/adrienchampion), original author
22+
- [@lenianiva](https://github.com/lenianiva), maintainer
23+
24+
## Contributors
2525

2626
- [@alex-ozdemir](https://github.com/alex-ozdemir)
2727

src/coll.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ where
178178
}
179179
/// An iterator visiting all elements.
180180
#[inline]
181-
pub fn iter(&self) -> ::std::collections::hash_set::Iter<HConsed<T::Inner>> {
181+
pub fn iter<'a>(&'a self) -> ::std::collections::hash_set::Iter<'a, HConsed<T::Inner>> {
182182
self.set.iter()
183183
}
184184
}
@@ -322,12 +322,14 @@ where
322322
}
323323
/// An iterator visiting all elements.
324324
#[inline]
325-
pub fn iter(&self) -> ::std::collections::hash_map::Iter<HConsed<T::Inner>, V> {
325+
pub fn iter<'a>(&'a self) -> ::std::collections::hash_map::Iter<'a, HConsed<T::Inner>, V> {
326326
self.map.iter()
327327
}
328328
/// An iterator visiting all elements.
329329
#[inline]
330-
pub fn iter_mut(&mut self) -> ::std::collections::hash_map::IterMut<HConsed<T::Inner>, V> {
330+
pub fn iter_mut<'a>(
331+
&'a mut self,
332+
) -> ::std::collections::hash_map::IterMut<'a, HConsed<T::Inner>, V> {
331333
self.map.iter_mut()
332334
}
333335
}
@@ -437,7 +439,7 @@ mod hash {
437439
impl HashU64 {
438440
/// Checks that a slice of bytes has the length of a `usize`. Only active
439441
/// in debug.
440-
#[cfg(debug)]
442+
#[cfg(debug_assertions)]
441443
#[inline(always)]
442444
fn test_bytes(bytes: &[u8]) {
443445
if bytes.len() != 8 {
@@ -451,13 +453,13 @@ mod hash {
451453
}
452454
/// Checks that a slice of bytes has the length of a `usize`. Only active
453455
/// in debug.
454-
#[cfg(not(debug))]
456+
#[cfg(not(debug_assertions))]
455457
#[inline(always)]
456458
fn test_bytes(_: &[u8]) {}
457459
}
458460
impl Hasher for HashU64 {
459461
fn finish(&self) -> u64 {
460-
unsafe { ::std::mem::transmute(self.buf) }
462+
u64::from_ne_bytes(self.buf)
461463
}
462464
fn write(&mut self, bytes: &[u8]) {
463465
Self::test_bytes(bytes);

src/hash_coll.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@
4242
//! be the natural one, *e.g.* `HConSet<Term>`.
4343
//!
4444
//! However, since `Term` is really an alias for `HConsed<RTerm>`, then if we wanted to declare
45-
//! `HConSet` as an alias for `HashSet` we would get `type HConSet<Inner> = HashSet< HConsed<Inner>
46-
//! >` (omitting the custom hasher). That is, our sets would have type `HConSet<RTerm>`, which is
47-
//! not very pretty. We could just define an alias though: `type TermSet = HConSet<RTerm>`, but it
48-
//! turns out it's better to wrap the actual set in a `struct` anyway. Mostly to be able to define
49-
//! `new` and `with_capacity` without relying on a trait (users would need to import) to do that.
45+
//! `HConSet` as an alias for `HashSet` we would get `type HConSet<Inner> = HashSet<HConsed<Inner>>`
46+
//! (omitting the custom hasher). That is, our sets would have type `HConSet<RTerm>`, which is not
47+
//! very pretty. We could just define an alias though: `type TermSet = HConSet<RTerm>`, but it turns
48+
//! out it's better to wrap the actual set in a `struct` anyway. Mostly to be able to define `new`
49+
//! and `with_capacity` without relying on a trait (users would need to import) to do that.
5050
//!
5151
//! So actually `HConsed` types automatically implement the internal `trait HashConsed { type Inner;
5252
//! }`. The sole purpose of this trait (currently) is to pass the inner type implicitly thanks to a
@@ -322,7 +322,7 @@ where
322322
{
323323
/// An iterator visiting all elements.
324324
#[inline]
325-
pub fn iter(&self) -> ::std::collections::hash_set::Iter<HConsed<T::Inner>> {
325+
pub fn iter<'a>(&'a self) -> ::std::collections::hash_set::Iter<'a, HConsed<T::Inner>> {
326326
self.set.iter()
327327
}
328328
}
@@ -520,12 +520,14 @@ where
520520
{
521521
/// An iterator visiting all elements.
522522
#[inline]
523-
pub fn iter(&self) -> ::std::collections::hash_map::Iter<HConsed<T::Inner>, V> {
523+
pub fn iter<'a>(&'a self) -> ::std::collections::hash_map::Iter<'a, HConsed<T::Inner>, V> {
524524
self.map.iter()
525525
}
526526
/// An iterator visiting all elements.
527527
#[inline]
528-
pub fn iter_mut(&mut self) -> ::std::collections::hash_map::IterMut<HConsed<T::Inner>, V> {
528+
pub fn iter_mut<'a>(
529+
&'a mut self,
530+
) -> ::std::collections::hash_map::IterMut<'a, HConsed<T::Inner>, V> {
529531
self.map.iter_mut()
530532
}
531533
}
@@ -643,7 +645,7 @@ mod hash {
643645
impl HashU64 {
644646
/// Checks that a slice of bytes has the length of a `usize`. Only active
645647
/// in debug.
646-
#[cfg(debug)]
648+
#[cfg(debug_assertions)]
647649
#[inline(always)]
648650
fn test_bytes(bytes: &[u8]) {
649651
if bytes.len() != 8 {
@@ -657,13 +659,13 @@ mod hash {
657659
}
658660
/// Checks that a slice of bytes has the length of a `usize`. Only active
659661
/// in debug.
660-
#[cfg(not(debug))]
662+
#[cfg(not(debug_assertions))]
661663
#[inline(always)]
662664
fn test_bytes(_: &[u8]) {}
663665
}
664666
impl Hasher for HashU64 {
665667
fn finish(&self) -> u64 {
666-
let block: u64 = unsafe { ::std::mem::transmute(self.buf) };
668+
let block: u64 = u64::from_ne_bytes(self.buf);
667669
// Multiply by random 64-bit prime to distribute
668670
block.wrapping_mul(0xDA5DF7A7BD02F2C7u64)
669671
}

src/hash_coll/hashers.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub mod p_hash {
5050
impl Hasher {
5151
/// Checks that a slice of bytes has the length of a `usize`. Only active
5252
/// in debug.
53-
#[cfg(debug)]
53+
#[cfg(debug_assertions)]
5454
#[inline(always)]
5555
fn test_bytes(bytes: &[u8]) {
5656
if bytes.len() != 8 {
@@ -64,13 +64,13 @@ pub mod p_hash {
6464
}
6565
/// Checks that a slice of bytes has the length of a `usize`. Only active
6666
/// in debug.
67-
#[cfg(not(debug))]
67+
#[cfg(not(debug_assertions))]
6868
#[inline(always)]
6969
fn test_bytes(_: &[u8]) {}
7070
}
7171
impl StdHasherExt for Hasher {
7272
fn finish(&self) -> u64 {
73-
let block: u64 = unsafe { ::std::mem::transmute(self.buf) };
73+
let block: u64 = u64::from_ne_bytes(self.buf);
7474
// Multiply by random 64-bit prime to distribute
7575
block.wrapping_mul(0xDA5DF7A7BD02F2C7u64)
7676
}
@@ -112,7 +112,7 @@ pub mod id_hash {
112112
impl Hasher {
113113
/// Checks that a slice of bytes has the length of a `usize`. Only active
114114
/// in debug.
115-
#[cfg(debug)]
115+
#[cfg(debug_assertions)]
116116
#[inline(always)]
117117
fn test_bytes(bytes: &[u8]) {
118118
if bytes.len() != 8 {
@@ -126,13 +126,13 @@ pub mod id_hash {
126126
}
127127
/// Checks that a slice of bytes has the length of a `usize`. Only active
128128
/// in debug.
129-
#[cfg(not(debug))]
129+
#[cfg(not(debug_assertions))]
130130
#[inline(always)]
131131
fn test_bytes(_: &[u8]) {}
132132
}
133133
impl StdHasherExt for Hasher {
134134
fn finish(&self) -> u64 {
135-
unsafe { ::std::mem::transmute(self.buf) }
135+
u64::from_ne_bytes(self.buf)
136136
}
137137
fn write(&mut self, bytes: &[u8]) {
138138
Self::test_bytes(bytes);

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@
213213
//! [lazy static]: https://crates.io/crates/lazy_static
214214
//! (lazy_static library on crates.io)
215215
216+
#![deny(warnings)]
217+
216218
use std::{
217219
borrow::Borrow,
218220
cmp::{Eq, Ord, Ordering, PartialEq, PartialOrd},
@@ -239,7 +241,7 @@ mod test;
239241
/// - `$hash_builder:expr` optional hash builder, an
240242
/// implementation of [`std::hash::BuildHasher`] ;
241243
/// - `$typ:typ,` type being hashconsed (the underlying type, not the
242-
/// hashconsed one) ;
244+
/// hashconsed one) ;
243245
#[macro_export]
244246
macro_rules! consign {
245247
(
@@ -353,7 +355,7 @@ impl<T> Eq for HConsed<T> {}
353355
impl<T> PartialOrd for HConsed<T> {
354356
#[inline]
355357
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
356-
self.uid.partial_cmp(&other.uid)
358+
Some(self.cmp(other))
357359
}
358360
}
359361
impl<T> Ord for HConsed<T> {
@@ -445,7 +447,7 @@ impl<T> Eq for WHConsed<T> {}
445447
impl<T> PartialOrd for WHConsed<T> {
446448
#[inline]
447449
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
448-
self.uid.partial_cmp(&other.uid)
450+
Some(self.cmp(other))
449451
}
450452
}
451453
impl<T> Ord for WHConsed<T> {
@@ -672,7 +674,7 @@ pub trait HashConsign<T: Hash>: Sized {
672674
/// Reserves capacity for at least `additional` more elements.
673675
fn reserve(self, additional: usize);
674676
}
675-
impl<'a, T: Hash + Eq + Clone, S: BuildHasher> HashConsign<T> for &'a mut HConsign<T, S> {
677+
impl<T: Hash + Eq + Clone, S: BuildHasher> HashConsign<T> for &mut HConsign<T, S> {
676678
fn mk_is_new(self, elm: T) -> (HConsed<T>, bool) {
677679
// If the element is known and upgradable return it.
678680
if let Some(hconsed) = self.get(&elm) {
@@ -745,7 +747,7 @@ macro_rules! get {
745747
};
746748
}
747749

748-
impl<'a, T: Hash + Eq + Clone> HashConsign<T> for &'a RwLock<HConsign<T>> {
750+
impl<T: Hash + Eq + Clone> HashConsign<T> for &RwLock<HConsign<T>> {
749751
/// If the element is already in the consign, only read access will be
750752
/// requested.
751753
fn mk_is_new(self, elm: T) -> (HConsed<T>, bool) {

0 commit comments

Comments
 (0)