diff --git a/Cargo.toml b/Cargo.toml index 2d0857e..cf3e7f3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,11 +10,11 @@ repository = "https://github.com/rust-fuzz/sancov" version = "0.1.0" [dependencies] -fxhash = { version = "0.2.1", optional = true } +rustc-hash = { version = "2.1.1", optional = true} sancov-sys = { path = "./sys", version = "0.1.0" } [features] -hash_increment = ["dep:fxhash"] +hash_increment = ["dep:rustc-hash"] [package.metadata.docs.rs] features = ["hash_increment"] diff --git a/src/lib.rs b/src/lib.rs index d8c12b8..3b27da2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,8 +3,12 @@ #![deny(missing_docs)] use core::cell::UnsafeCell; +#[cfg(feature = "hash_increment")] +use core::hash::Hasher; use core::ops::Index; use core::sync::atomic::{AtomicU8, Ordering}; +#[cfg(feature = "hash_increment")] +use rustc_hash::FxHasher; use sancov_sys as sys; /// An collection of `N` counters. @@ -167,7 +171,9 @@ impl Counters { T: ?Sized + core::hash::Hash, { assert_ne!(N, 0); - let i = fxhash::hash(x) % N; + let mut hasher = FxHasher::default(); + x.hash(&mut hasher); + let i = hasher.finish() as usize % N; self[i].increment(); } }