Add check for if a shard_amount is a power of two. (#186)

Signed-off-by: Leo Lu <luyuxuanleo@gmail.com>
This commit is contained in:
Leo 2022-03-01 17:26:30 +08:00 committed by GitHub
parent 6321c886b4
commit 23f3d04335
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 0 deletions

View File

@ -250,6 +250,7 @@ impl<'a, K: 'a + Eq + Hash, V: 'a, S: BuildHasher + Clone> DashMap<K, V, S> {
shard_amount: usize,
) -> Self {
assert!(shard_amount > 0);
assert!(shard_amount.is_power_of_two());
let shift = util::ptr_size_bits() - ncb(shard_amount);