From 93f43790af6b6bd6f7f781640c8e27eb88fe6ddf Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Thu, 15 Sep 2022 21:06:04 +0800 Subject: [PATCH] Fix bloom filter on 32-bit arch. --- src/types/bloom_filter.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/types/bloom_filter.rs b/src/types/bloom_filter.rs index 61a1d360..9400879b 100644 --- a/src/types/bloom_filter.rs +++ b/src/types/bloom_filter.rs @@ -7,8 +7,11 @@ use std::{ ops::{Add, AddAssign}, }; +/// Number of bits for a `usize`. +const USIZE_BITS: usize = mem::size_of::() * 8; + /// Number of `usize` values required for 256 bits. -const SIZE: usize = (256 / 8) / mem::size_of::(); +const SIZE: usize = 256 / USIZE_BITS; /// A simple bloom filter implementation for `u64` hash values only - i.e. all 64 bits are assumed /// to be relatively random. @@ -26,7 +29,7 @@ impl BloomFilterU64 { #[must_use] const fn calc_hash(value: u64) -> (usize, usize) { let hash = (value & 0x00ff) as usize; - (hash / 64, 0x01 << (hash % 64)) + (hash / USIZE_BITS, 0x01 << (hash % USIZE_BITS)) } /// Create a new [`BloomFilterU64`]. #[inline(always)]