Skip to content

Commit

Permalink
Bump ahash and mask from public API
Browse files Browse the repository at this point in the history
This is a breaking change.
However, at least future bumps of ahash now won't be.

Closes #119.
  • Loading branch information
jonhoo committed Feb 11, 2024
1 parent ff762e8 commit 7b4730b
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 6 deletions.
63 changes: 60 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ serde = {version = "1.0.105", optional = true}
seize = "0.2.1"

[dependencies.ahash]
version = "0.7.6"
version = "0.8.4"
# NOTE: we enable just compile-time-rng to get a reasonable ahash::RandomState::default
# without _also_ forcing consumers of flurry into using runtime-rng. they can, however,
# still opt into that feature if they wish, which will take precedence over compile-time-rng
# as per the ahash docs.
default-features = false
features = ["compile-time-rng"]

# for minimal-versions
[target.'cfg(any())'.dependencies]
Expand Down
87 changes: 85 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,90 @@ pub use map_ref::HashMapRef;
pub use set::HashSet;
pub use set_ref::HashSetRef;

pub use seize::Guard;

/// Default hash builder for [`HashMap`].
// NOTE: This and the below exists solely to avoid ahash being part of the public flurry API,
// so that we can bump the ahash major version without bumping flurry's major version.
#[derive(Debug, Clone, Default)]
#[repr(transparent)]
pub struct DefaultHashBuilder(ahash::RandomState);

/// Default hasher for [`HashMap`].
pub type DefaultHashBuilder = ahash::RandomState;
#[derive(Debug, Clone)]
#[repr(transparent)]
pub struct DefaultHasher(ahash::AHasher);

pub use seize::Guard;
impl std::hash::BuildHasher for DefaultHashBuilder {
type Hasher = DefaultHasher;

fn build_hasher(&self) -> Self::Hasher {
DefaultHasher(self.0.build_hasher())
}

// NOTE: also implement hash_one so we can forward to ahash::RandomState's optimized impl.
fn hash_one<T: std::hash::Hash>(&self, x: T) -> u64
where
Self: Sized,
{
self.0.hash_one(x)
}
}

impl std::hash::Hasher for DefaultHasher {
fn finish(&self) -> u64 {
self.0.finish()
}

fn write(&mut self, bytes: &[u8]) {
self.0.write(bytes)
}

fn write_u8(&mut self, i: u8) {
self.0.write_u8(i)
}

fn write_u16(&mut self, i: u16) {
self.0.write_u16(i)
}

fn write_u32(&mut self, i: u32) {
self.0.write_u32(i)
}

fn write_u64(&mut self, i: u64) {
self.0.write_u64(i)
}

fn write_u128(&mut self, i: u128) {
self.0.write_u128(i)
}

fn write_usize(&mut self, i: usize) {
self.0.write_usize(i)
}

fn write_i8(&mut self, i: i8) {
self.0.write_i8(i)
}

fn write_i16(&mut self, i: i16) {
self.0.write_i16(i)
}

fn write_i32(&mut self, i: i32) {
self.0.write_i32(i)
}

fn write_i64(&mut self, i: i64) {
self.0.write_i64(i)
}

fn write_i128(&mut self, i: i128) {
self.0.write_i128(i)
}

fn write_isize(&mut self, i: isize) {
self.0.write_isize(i)
}
}

0 comments on commit 7b4730b

Please sign in to comment.