Commit before debugging bloom.py
This commit is contained in:
parent
496e2f823f
commit
b5cd1d9702
@ -69,7 +69,6 @@ class BloomFilter():
|
|||||||
r = self._locations
|
r = self._locations
|
||||||
a = self.fnv_1a(v)
|
a = self.fnv_1a(v)
|
||||||
b = self.fnv_1a_b(a)
|
b = self.fnv_1a_b(a)
|
||||||
print(b)
|
|
||||||
i = 0
|
i = 0
|
||||||
x = a % self.m
|
x = a % self.m
|
||||||
while i < self.k:
|
while i < self.k:
|
||||||
@ -115,6 +114,13 @@ class BloomFilter():
|
|||||||
v = (v & 0x33333333) + ((v >> 2) & 0x33333333)
|
v = (v & 0x33333333) + ((v >> 2) & 0x33333333)
|
||||||
return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24
|
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):
|
def fnv_1a(self, v):
|
||||||
"""
|
"""
|
||||||
Fowler/Noll/Vo hashing.
|
Fowler/Noll/Vo hashing.
|
||||||
@ -126,25 +132,25 @@ class BloomFilter():
|
|||||||
c = ord(v[i])
|
c = ord(v[i])
|
||||||
d = c & 0xff000000
|
d = c & 0xff000000
|
||||||
if d:
|
if d:
|
||||||
a ^= d >> 24
|
a = self.xor32bits(a, d >> 24)
|
||||||
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24)
|
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24)
|
||||||
d = c & 0xff0000
|
d = c & 0xff0000
|
||||||
if d:
|
if d:
|
||||||
a ^= d >> 16
|
a = self.xor32bits(a, d >> 16)
|
||||||
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24)
|
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24)
|
||||||
d = c & 0xff00
|
d = c & 0xff00
|
||||||
if d:
|
if d:
|
||||||
a ^= d >> 8
|
a = self.xor32bits(a, d >> 8)
|
||||||
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24)
|
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24)
|
||||||
a ^= c & 0xff
|
a = self.xor32bits(a, c & 0xff)
|
||||||
print(a ^ (c & 0xff))
|
|
||||||
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24)
|
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24)
|
||||||
|
print(a << 24)
|
||||||
i += 1
|
i += 1
|
||||||
# From http://home.comcast.net/~bretm/hash/6.html
|
# From http://home.comcast.net/~bretm/hash/6.html
|
||||||
a += a << 13
|
a += a << 13
|
||||||
a ^= a >> 7
|
a = self.xor32bits(a, a >> 7)
|
||||||
a += a << 3
|
a += a << 3
|
||||||
a ^= a >> 17
|
a = self.xor32bits(a, a >> 17)
|
||||||
a += a << 5
|
a += a << 5
|
||||||
return a & 0xffffffff
|
return a & 0xffffffff
|
||||||
|
|
||||||
@ -154,9 +160,8 @@ class BloomFilter():
|
|||||||
"""
|
"""
|
||||||
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24)
|
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24)
|
||||||
a += a << 13
|
a += a << 13
|
||||||
a ^= a >> 7
|
a = self.xor32bits(a, a >> 7)
|
||||||
a += a << 3
|
a += a << 3
|
||||||
a ^= a >> 17
|
a = self.xor32bits(a, a >> 17)
|
||||||
a += a << 5
|
a += a << 5
|
||||||
print(a)
|
|
||||||
return a & 0xffffffff
|
return a & 0xffffffff
|
||||||
|
@ -134,6 +134,7 @@
|
|||||||
}
|
}
|
||||||
a ^= c & 0xff;
|
a ^= c & 0xff;
|
||||||
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24);
|
a += (a << 1) + (a << 4) + (a << 7) + (a << 8) + (a << 24);
|
||||||
|
console.log(a << 24)
|
||||||
}
|
}
|
||||||
// From http://home.comcast.net/~bretm/hash/6.html
|
// From http://home.comcast.net/~bretm/hash/6.html
|
||||||
a += a << 13;
|
a += a << 13;
|
||||||
|
Loading…
Reference in New Issue
Block a user