From b5cd1d9702bde4bf9fd2142ce556ef68416f891f Mon Sep 17 00:00:00 2001 From: Phyks Date: Tue, 28 Oct 2014 02:45:57 +0100 Subject: [PATCH] Commit before debugging bloom.py --- index_generation/bloom.py | 27 ++++++++++++++++----------- js/bloom.js | 1 + 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/index_generation/bloom.py b/index_generation/bloom.py index 562c2f1..b5d9050 100644 --- a/index_generation/bloom.py +++ b/index_generation/bloom.py @@ -69,7 +69,6 @@ class BloomFilter(): r = self._locations a = self.fnv_1a(v) b = self.fnv_1a_b(a) - print(b) i = 0 x = a % self.m while i < self.k: @@ -115,6 +114,13 @@ class BloomFilter(): v = (v & 0x33333333) + ((v >> 2) & 0x33333333) return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24 + def xor32bits(self, a, b): + # Cf https://stackoverflow.com/questions/1694507/difference-between-operator-in-js-and-python + m = (a ^ b) % (1 << 32) + if m > (1 << 16): + m -= 1 << 32 + return m + def fnv_1a(self, v): """ Fowler/Noll/Vo hashing. @@ -126,25 +132,25 @@ class BloomFilter(): c = ord(v[i]) d = c & 0xff000000 if d: - a ^= d >> 24 + a = self.xor32bits(a, d >> 24) a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24) d = c & 0xff0000 if d: - a ^= d >> 16 + a = self.xor32bits(a, d >> 16) a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24) d = c & 0xff00 if d: - a ^= d >> 8 + a = self.xor32bits(a, d >> 8) a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24) - a ^= c & 0xff - print(a ^ (c & 0xff)) + a = self.xor32bits(a, c & 0xff) a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24) + print(a << 24) i += 1 # From http://home.comcast.net/~bretm/hash/6.html a += a << 13 - a ^= a >> 7 + a = self.xor32bits(a, a >> 7) a += a << 3 - a ^= a >> 17 + a = self.xor32bits(a, a >> 17) a += a << 5 return a & 0xffffffff @@ -154,9 +160,8 @@ class BloomFilter(): """ a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24) a += a << 13 - a ^= a >> 7 + a = self.xor32bits(a, a >> 7) a += a << 3 - a ^= a >> 17 + a = self.xor32bits(a, a >> 17) a += a << 5 - print(a) return a & 0xffffffff diff --git a/js/bloom.js b/js/bloom.js index e0cf72e..59b56cd 100644 --- a/js/bloom.js +++ b/js/bloom.js @@ -134,6 +134,7 @@ } a ^= c & 0xff; a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24); + console.log(a << 24) } // From http://home.comcast.net/~bretm/hash/6.html a += a << 13;