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

Function OptimalNumOfBits

cpp/src/parquet/bloom_filter.h:245–273  ·  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

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