From fb9ec01fdbe5107ec6e5453ac48f2d322d2ac4ec Mon Sep 17 00:00:00 2001 From: Jason Davies Date: Tue, 6 Dec 2011 23:37:05 +0000 Subject: [PATCH] Rearrange things a bit. --- bloomfilter.js | 54 +++++++++++++++++++++++++------------------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/bloomfilter.js b/bloomfilter.js index 47e06bf..9bac70b 100644 --- a/bloomfilter.js +++ b/bloomfilter.js @@ -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);