1
1
mirror of https://github.com/rui314/mold.git synced 2024-08-16 08:20:23 +03:00
mold/common/hyperloglog.cc

21 lines
453 B
C++
Raw Normal View History

// This file implements HyperLogLog algorithm, which estimates
// the number of unique items in a given multiset.
//
// For more info, read
// https://engineering.fb.com/2018/12/13/data-infrastructure/hyperloglog
2023-01-16 10:26:52 +03:00
#include "common.h"
#include <cmath>
namespace mold {
i64 HyperLogLog::get_cardinality() const {
double z = 0;
for (i64 val : buckets)
z += std::ldexp(1.0, -val);
return ALPHA * NBUCKETS * NBUCKETS / z;
}
} // namespace mold