-
Notifications
You must be signed in to change notification settings - Fork 18
/
auto_tune_bloom.cc
87 lines (72 loc) · 1.79 KB
/
auto_tune_bloom.cc
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
double _p_from_kr(double k, double r) {
return pow(1 - exp(-k / r), k);
}
double _k_from_r(double r) {
return round(log(2) * r);
}
double _r_from_pk(double p,double k) {
return -k / log(1 - exp(log(p) / k));
}
double _r_from_mn(double m,double n) {
return m / n;
}
std::pair<double,double> km_from_np(double n,double p) {
double m = ceil(n * log(p) / log(1 / pow(2, log(2))));
double r = _r_from_mn(m, n);
double k = _k_from_r(r);
p = _p_from_kr(k, r);
return std::make_pair(k,m);
}
std::pair<double,double> kp_from_mn(double m,double n) {
double r = _r_from_mn(m, n);
double k = _k_from_r(r);
double p = _p_from_kr(k, r);
return std::make_pair(k,p);
}
std::pair<double,double> kn_from_mp(double m,double p) {
double n = ceil((m * log(pow(1 / 2, log(2))) / log(p)));
double r = _r_from_mn(m, n);
double k = _k_from_r(r);
p = _p_from_kr(k, r);
return std::make_pair(k,n);
}
double p_from_kmn(double k,double m,double n) {
double p = _p_from_kr(k, _r_from_mn(m, n));
return p;
}
double n_from_kmp(double k,double m,double p) {
double r = _r_from_pk(p, k);
double n = ceil(m / r);
return n;
}
double m_from_knp(double k,double n,double p) {
double r = _r_from_pk(p, k);
double m = ceil(n * r);
return m;
}
int main(int argc,char** argv){
if(argc != 2){
fprintf(stderr,"Usage: %s <topk>\n",argv[0]);
return 1;
}
double topk = atof(argv[1]);
double n = topk * 12.897;
int maxn = 15;
for(int i = 1;i <= maxn;++i){
double m = 64 * (1 << i);
auto tmp = kp_from_mn(m,n);
double k = tmp.first;
double p = tmp.second;
if(p < 0.03){
printf("bit %d %d hash %d p %f\n",1 << i,i,(int)round(k),p);
break;
}
if(i == maxn)
printf("bit %d %d hash %d p %f\n",1 << i,i,(int)round(k),p);
}
return 0;
}