-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbloomchart.html
76 lines (68 loc) · 2.36 KB
/
bloomchart.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
<html>
<head>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(redraw);
function drawChart(rawData, numElements) {
var data = google.visualization.arrayToDataTable(rawData);
var options = {
title: 'Bloom Filter False Positive Probabilities (n=' +
numElements + ')',
hAxis: {title: 'Bits (m)',
titleTextStyle: {color: '#333'},
logScale: true},
vAxis: {title: 'p', minValue: 0}
};
var chart = new google.visualization.AreaChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
function falsePositiveP(m, n, k) {
return Math.pow(1.0 - Math.exp(-k * n / m), k);
}
var hashes = [1, 2, 4];
var bitCounts = [512, 1024, 2048, 4096, 8192, 16384, 32768, 65536];
function redraw() {
var headers = ["Bits (m)"];
var rawData = [];
var numElements = parseInt(document.getElementById("numelements").value);
for (var i = 0; i < hashes.length; i++) {
headers.push(hashes[i] + " hashes (k=" + hashes[i] + ")");
}
headers.push("k = (m / n) * ln(2)")
rawData.push(headers)
for (var i = 0; i < bitCounts.length; i++) {
var bits = bitCounts[i];
var row = [bits];
for (var j = 0; j < hashes.length; j++) {
row.push(falsePositiveP(bits, numElements, hashes[j]));
}
row.push(falsePositiveP(bits, numElements,
(bits / numElements) * Math.log(2)));
rawData.push(row);
}
drawChart(rawData, numElements);
}
</script>
</head>
<body>
<form onsubmit="redraw(); return false;">
<table>
<tr>
<td>
<label>Elements (n):</label>
</td>
<td>
<input id="numelements" type=text value="100"></input>
</td>
</tr>
<tr>
<td>
<button type="submit">Redraw</button>
</td>
</tr>
</table>
</form>
<div id="chart_div" style="width: 900px; height: 500px;"></div>
</body>
</html>