-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
executable file
·128 lines (107 loc) · 2.92 KB
/
index.html
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Bloom Filter Calculator</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h1>Bloom Filter Calculator</h1>
<p>
Enter the size of the bloom filter and the acceptable error rate
and you will be shown the optimal configuration. See
<a href="http://stackoverflow.com/questions/658439/how-many-hash-functions-does-my-bloom-filter-need">
this stack overflow post
</a>
on how this is computed.
</p>
<form class="form-horizontal">
<fieldset>
<div class="form-group">
<label class="col-md-4 control-label" for="count">
Count ( <em>n</em> )
</label>
<div class="col-md-4">
<input id="count" placeholder="300" class="form-control input-md" type="text">
<span class="help-block">
Number of items you expect to add to the filter. You can use
basic arithmetic.</span>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="error">
Error ( <em>p</em> )
</label>
<div class="col-md-4">
<input id="error" placeholder="0.001" class="form-control input-md" type="text">
<span class="help-block">Max allowed error (0.01 = 1%)</span>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="funcs">
Functions ( <em>k</em> )
</label>
<div class="col-md-4">
<div id="funcs" class="form-control">
</div>
<span class="help-block">Number of hashing functions</span>
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label" for="size">
Size ( <em>m</em> )
</label>
<div class="col-md-4">
<div id="size" class="form-control">
</div>
<span class="help-block">Size of the bloom filter. Usually denoted as
<em>m</em> bits.</span>
</div>
</div>
</fieldset>
</form>
</div>
<script>
$(function () {
var ln = Math.log;
var pow = Math.pow;
var ceil = Math.ceil;
var n = 0, p = 0, k = 0, m = 0;
function format(x) {
x = String(x);
var n = x.indexOf('.');
if (n <= 0) { return x; }
return x.substr(0, n + 3);
}
function evaluate(selector) {
var x = $(selector).val();
if (x.indexOf('*') > 0 || x.indexOf('+') > 0 || x.indexOf('/') > 0) {
x = eval(x);
}
return Number(x);
}
function calculate() {
n = evaluate("#count");
p = evaluate("#error")
m = -n * ln(p) / (pow(ln(2), 2));
k = m/n * ln(2);
$("#funcs").text(format(k));
var bits = ceil(m);
var kilobits = bits / 1024;
var kilobytes = (bits / 8) / 1024;
$("#size").text(
String(bits) + " bits " +
"(" + format(kilobytes) + " KB)"
);
}
$("#count,#error").keyup(function (e) {
calculate();
});
calculate();
});
</script>
</body>
</html>