Rearrange things a bit.

This commit is contained in:
Jason Davies 2011-12-06 23:37:05 +00:00
parent b05df25115
commit fb9ec01fdb
1 changed files with 27 additions and 27 deletions

View File

@ -1,4 +1,8 @@
(function(exports) {
exports.BloomFilter = BloomFilter;
exports.fnv_1a = fnv_1a;
exports.fnv_1a_b = fnv_1a_b;
function BloomFilter(m, k) {
this.m = m;
this.k = k;
@ -8,30 +12,6 @@
while (++i < n) buckets[i] = 0;
}
// Fowler/Noll/Vo hashing.
function fnv_1a(v) {
var n = v.length,
a = 2166136261,
c,
i = -1;
while (++i < n) {
c = v.charCodeAt(i);
a ^= (c & 0xff00) >> 8;
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24);
a &= 0xffffffff;
a ^= c & 0xff;
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24);
a &= 0xffffffff;
}
return a;
}
// One additional iteration of FNV, given a hash.
function fnv_1a_b(a) {
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24);
return a & 0xffffffff;
}
// See http://willwhim.wordpress.com/2011/09/03/producing-n-hash-functions-by-hashing-only-once/
BloomFilter.prototype.locations = function(v) {
var k = this.k,
@ -68,7 +48,27 @@
return true;
};
exports.BloomFilter = BloomFilter;
exports.fnv_1a = fnv_1a;
exports.fnv_1a_b = fnv_1a_b;
// Fowler/Noll/Vo hashing.
function fnv_1a(v) {
var n = v.length,
a = 2166136261,
c,
i = -1;
while (++i < n) {
c = v.charCodeAt(i);
a ^= (c & 0xff00) >> 8;
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24);
a &= 0xffffffff;
a ^= c & 0xff;
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24);
a &= 0xffffffff;
}
return a;
}
// One additional iteration of FNV, given a hash.
function fnv_1a_b(a) {
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24);
return a & 0xffffffff;
}
})(typeof exports !== "undefined" ? exports : this);