-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
43 lines (34 loc) · 1.17 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <set>
#include <random>
#include <iostream>
#include "hll/hyper_log_log.hxx"
double relative_error(int expected, int got) {
return abs(got - expected) / (double) expected;
}
int main() {
std::random_device rd;
std::mt19937 gen(rd());
constexpr int N = (int) 1e6;
double error_count = 0.0;
int count = 0;
hll::hyper_log_log<int, 12> counter{};
for (int k : {100, 1000, 10000, N / 10, N, N * 10, N * 100, N * 1000}) {
std::uniform_int_distribution<> dis(1, k);
std::set<int> all;
for (int i = 0; i < N; i++) {
int value = dis(gen);
all.insert(value);
counter.add(value);
}
int expected = (int) all.size();
int counter_result = counter.count();
double error = relative_error(expected, counter_result);
error_count += error;
count += 1;
printf("%d numbers in range [1 .. %d], %d uniq, %d result, %.5f relative error\n", N, k, expected, counter_result, error);
counter.clear();
}
printf("Average error: %.5f\n", error_count / count);
printf("Paper estimated error: %.5f\n", counter.get_relative_error());
return 0;
}