Use typed arrays.

This commit is contained in:
Jason Davies 2011-12-06 23:46:44 +00:00
parent fb9ec01fdb
commit 445e617a78
1 changed files with 11 additions and 2 deletions

View File

@ -6,9 +6,18 @@
function BloomFilter(m, k) {
this.m = m;
this.k = k;
var buckets = this.buckets = [],
var buckets,
n = Math.ceil(m / k),
i = -1;
try {
var buffer = new ArrayBuffer(4 * n),
kbuffer = new ArrayBuffer(4 * k);
buckets = this.buckets = new Uint32Array(buffer);
this._locations = new Uint32Array(kbuffer);
} catch (e) {
buckets = this.buckets = [];
this._locations = [];
}
while (++i < n) buckets[i] = 0;
}
@ -16,7 +25,7 @@
BloomFilter.prototype.locations = function(v) {
var k = this.k,
m = this.m,
r = [],
r = this._locations,
a = fnv_1a(v),
b = fnv_1a_b(a),
i = -1;