MCPcopy Create free account
hub / github.com/apache/arrow / OptimalNumOfBits

Function OptimalNumOfBits

cpp/src/parquet/bloom_filter.h:249–277  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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;

Callers 2

OptimalNumOfBytesFunction · 0.85
TESTFunction · 0.85

Calls 1

NextPower2Function · 0.85

Tested by 1

TESTFunction · 0.68