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

Method NumFoldsForTargetFpp

cpp/src/parquet/bloom_filter.cc:396–426  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394}
395
396uint32_t BlockSplitBloomFilter::NumFoldsForTargetFpp(double target_fpp,
397 double avg_fill) const {
398 const uint32_t num_blocks = NumBlocks();
399 if (num_blocks < 2) {
400 return 0;
401 }
402 // Number of blocks is a power of two
403 DCHECK_EQ(num_blocks & (num_blocks - 1), 0);
404
405 // Estimate the fill rate after folding from the current average fill rate.
406 // Folding ORs block groups together, so each fold changes the estimated fill rate
407 // from f to 1 - (1 - f)^2. A membership check tests kBitsSetPerBlock bits, making
408 // the estimated FPP equal to std::pow(folded_fill_rate, kBitsSetPerBlock).
409 //
410 // See also: Sailhan and Stehr, "Folding and Unfolding Bloom Filters", 2012:
411 // https://hal.science/hal-01126174v1
412 const auto max_folds = static_cast<uint32_t>(std::countr_zero(num_blocks));
413
414 uint32_t num_folds = 0;
415 double unset_probability_after_folds = 1.0 - avg_fill;
416 for (uint32_t i = 0; i < max_folds; ++i) {
417 unset_probability_after_folds *= unset_probability_after_folds;
418 const double folded_fill_rate = 1.0 - unset_probability_after_folds;
419 const double estimated_fpp = std::pow(folded_fill_rate, kBitsSetPerBlock);
420 if (estimated_fpp > target_fpp) {
421 break;
422 }
423 ++num_folds;
424 }
425 return num_folds;
426}
427
428void BlockSplitBloomFilter::Fold(uint32_t num_folds) {
429 DCHECK_GT(num_folds, 0);

Callers

nothing calls this directly

Calls 1

NumBlocksFunction · 0.85

Tested by

no test coverage detected