Skip to content

Commit

Permalink
Resolve merge conflict.
Browse files Browse the repository at this point in the history
  • Loading branch information
orlp committed May 28, 2024
2 parents 4cb9c7c + 0773e83 commit 0a95d9d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "rustc-hash"
version = "1.1.0"
version = "1.2.0"
authors = ["The Rust Project Developers"]
description = "A speedy, non-cryptographic hashing algorithm used by rustc"
license = "Apache-2.0/MIT"
readme = "README.md"
keywords = ["hash", "hasher", "fxhash", "rustc"]
repository = "https://github.com/rust-lang/rustc-hash"
edition = "2018"
edition = "2021"

[features]
default = ["std"]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ The `std` feature is on by default to enable collections.
It can be turned off in `Cargo.toml` like so:

```toml
rustc-hash = { version = "1.1", default-features = false }
rustc-hash = { version = "1.2", default-features = false }
```
32 changes: 23 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,18 @@ mod random_state;

mod seeded_state;

use core::convert::TryInto;
use core::default::Default;
#[cfg(feature = "std")]
use core::hash::BuildHasherDefault;
use core::hash::Hasher;
use core::hash::{BuildHasher, Hasher};
#[cfg(feature = "std")]
use std::collections::{HashMap, HashSet};

/// Type alias for a hash map that uses the Fx hashing algorithm.
#[cfg(feature = "std")]
pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
pub type FxHashMap<K, V> = HashMap<K, V, FxBuildHasher>;

/// Type alias for a hash set that uses the Fx hashing algorithm.
#[cfg(feature = "std")]
pub type FxHashSet<V> = HashSet<V, BuildHasherDefault<FxHasher>>;
pub type FxHashSet<V> = HashSet<V, FxBuildHasher>;

#[cfg(feature = "rand")]
pub use random_state::{FxHashMapRand, FxHashSetRand, FxRandomState};
Expand Down Expand Up @@ -297,13 +294,30 @@ fn hash_bytes(bytes: &[u8]) -> u64 {
multiply_mix(s0, s1) ^ (len as u64)
}

/// An implementation of [`BuildHasher`] that produces [`FxHasher`]s.
///
/// ```
/// use std::hash::BuildHasher;
/// use rustc_hash::FxBuildHasher;
/// assert_ne!(FxBuildHasher.hash_one(1), FxBuildHasher.hash_one(2));
/// ```
#[derive(Copy, Clone, Default)]
pub struct FxBuildHasher;

impl BuildHasher for FxBuildHasher {
type Hasher = FxHasher;
fn build_hasher(&self) -> FxHasher {
FxHasher::default()
}
}

#[cfg(test)]
mod tests {
#[cfg(not(any(target_pointer_width = "64", target_pointer_width = "32")))]
compile_error!("The test suite only supports 64 bit and 32 bit usize");

use crate::FxHasher;
use core::hash::{BuildHasher, BuildHasherDefault, Hash, Hasher};
use crate::{FxBuildHasher, FxHasher};
use core::hash::{BuildHasher, Hash, Hasher};

macro_rules! test_hash {
(
Expand All @@ -312,7 +326,7 @@ mod tests {
)*
) => {
$(
assert_eq!(BuildHasherDefault::<FxHasher>::default().hash_one($value), $result);
assert_eq!(FxBuildHasher.hash_one($value), $result);
)*
};
}
Expand Down

0 comments on commit 0a95d9d

Please sign in to comment.