Calculate optimal size according to the number of distinct values and false positive probability. @param ndv The number of distinct values. @param fpp The false positive probability. @return it always return a value between kMinimumBloomFilterBytes * 8 and kMaximumBloomFilterBytes * 8, and the return value is always a power of 16
| 247 | /// @return it always return a value between kMinimumBloomFilterBytes * 8 and |
| 248 | /// kMaximumBloomFilterBytes * 8, and the return value is always a power of 16 |
| 249 | static uint32_t OptimalNumOfBits(uint64_t ndv, double fpp) { |
| 250 | ARROW_DCHECK(fpp > 0.0 && fpp < 1.0); |
| 251 | const double m = -8.0 * ndv / log(1 - pow(fpp, 1.0 / 8)); |
| 252 | uint32_t num_bits; |
| 253 | |
| 254 | // Handle overflow. |
| 255 | if (m < 0 || m > kMaximumBloomFilterBytes << 3) { |
| 256 | num_bits = static_cast<uint32_t>(kMaximumBloomFilterBytes << 3); |
| 257 | } else { |
| 258 | num_bits = static_cast<uint32_t>(m); |
| 259 | } |
| 260 | |
| 261 | // Round up to lower bound |
| 262 | if (num_bits < kMinimumBloomFilterBytes << 3) { |
| 263 | num_bits = kMinimumBloomFilterBytes << 3; |
| 264 | } |
| 265 | |
| 266 | // Get next power of 2 if bits is not power of 2. |
| 267 | if ((num_bits & (num_bits - 1)) != 0) { |
| 268 | num_bits = static_cast<uint32_t>(::arrow::bit_util::NextPower2(num_bits)); |
| 269 | } |
| 270 | |
| 271 | // Round down to upper bound |
| 272 | if (num_bits > kMaximumBloomFilterBytes << 3) { |
| 273 | num_bits = kMaximumBloomFilterBytes << 3; |
| 274 | } |
| 275 | |
| 276 | return num_bits; |
| 277 | } |
| 278 | |
| 279 | bool FindHash(uint64_t hash) const override; |
| 280 | void InsertHash(uint64_t hash) override; |