Skip to content

Commit

Permalink
Merge pull request #41 from xermicus/fix-nostd
Browse files Browse the repository at this point in the history
Bugfix: fix no_std builds
  • Loading branch information
WaffleLapkin committed May 29, 2024
2 parents 0773e83 + 38d9373 commit 1c85035
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ pub type FxHashSet<V> = HashSet<V, FxBuildHasher>;
#[cfg(feature = "rand")]
pub use random_state::{FxHashMapRand, FxHashSetRand, FxRandomState};

pub use seeded_state::{FxHashMapSeed, FxHashSetSeed, FxSeededState};
pub use seeded_state::FxSeededState;
#[cfg(feature = "std")]
pub use seeded_state::{FxHashMapSeed, FxHashSetSeed};

/// A speedy hash algorithm for use within rustc. The hashmap in liballoc
/// by default uses SipHash which isn't quite as speedy as we want. In the
Expand Down
19 changes: 8 additions & 11 deletions src/seeded_state.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::collections::{HashMap, HashSet};

use crate::FxHasher;

/// Type alias for a hashmap using the `fx` hash algorithm with [`FxSeededState`].
pub type FxHashMapSeed<K, V> = HashMap<K, V, FxSeededState>;
#[cfg(feature = "std")]
pub type FxHashMapSeed<K, V> = std::collections::HashMap<K, V, FxSeededState>;

/// Type alias for a hashmap using the `fx` hash algorithm with [`FxSeededState`].
pub type FxHashSetSeed<V> = HashSet<V, FxSeededState>;
#[cfg(feature = "std")]
pub type FxHashSetSeed<V> = std::collections::HashSet<V, FxSeededState>;

/// [`FxSetState`] is an alternative state for `HashMap` types, allowing to use [`FxHasher`] with a set seed.
///
Expand Down Expand Up @@ -41,16 +41,13 @@ impl core::hash::BuildHasher for FxSeededState {
mod tests {
use core::hash::BuildHasher;

use crate::{FxHashMapSeed, FxSeededState};
use crate::FxSeededState;

#[test]
fn different_states_are_different() {
let a = FxHashMapSeed::<&str, u32>::with_hasher(FxSeededState::with_seed(1));
let b = FxHashMapSeed::<&str, u32>::with_hasher(FxSeededState::with_seed(2));
let a = FxSeededState::with_seed(1);
let b = FxSeededState::with_seed(2);

assert_ne!(
a.hasher().build_hasher().hash,
b.hasher().build_hasher().hash
);
assert_ne!(a.build_hasher().hash, b.build_hasher().hash);
}
}

0 comments on commit 1c85035

Please sign in to comment.