Commit before debugging bloom.py

This commit is contained in:
Phyks 2014-10-28 02:45:57 +01:00
parent 496e2f823f
commit b5cd1d9702
2 changed files with 17 additions and 11 deletions

View File

@ -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

View File

@ -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;