diff --git a/Cargo.toml b/Cargo.toml index e251311..84f14f1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,7 +18,6 @@ raw-api = [] no_std = ["hashbrown"] [dependencies] -num_cpus = "1.13.0" ahash = "0.3.8" serde = { version = "1.0.114", optional = true, features = ["derive"] } cfg-if = "0.1.10" diff --git a/src/lib.rs b/src/lib.rs index 4232095..b832e29 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -49,13 +49,8 @@ cfg_if! { } } -fn shard_amount() -> usize { - (num_cpus::get() * 4).next_power_of_two() -} - -fn ncb(shard_amount: usize) -> usize { - shard_amount.trailing_zeros() as usize -} +const SHARD_AMOUNT: usize = 8; +const NCB: usize = SHARD_AMOUNT.trailing_zeros() as usize; /// DashMap is an implementation of a concurrent associative array/hashmap in Rust. /// @@ -172,17 +167,15 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone> DashMap { /// ``` pub fn with_capacity_and_hasher(mut capacity: usize, hasher: S) -> Self { - let shard_amount = shard_amount(); - - let shift = util::ptr_size_bits() - ncb(shard_amount); + let shift = util::ptr_size_bits() - NCB; if capacity != 0 { - capacity = (capacity + (shard_amount - 1)) & !(shard_amount - 1); + capacity = (capacity + (SHARD_AMOUNT - 1)) & !(SHARD_AMOUNT - 1); } - let cps = capacity / shard_amount; + let cps = capacity / SHARD_AMOUNT; - let shards = (0..shard_amount) + let shards = (0..SHARD_AMOUNT) .map(|_| RwLock::new(HashMap::with_capacity_and_hasher(cps, hasher.clone()))) .collect();