-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbloom.py
49 lines (37 loc) · 888 Bytes
/
bloom.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python
#coding: utf8
#Author: chenyunyun<[email protected]>
#在redis的基础上构建的bloom filter
import redis
class Bloom(object):
def __init__(self, conn, name, capacity, error_rate=0.001):
self.conn = conn
def __contains__(self, key):
pass
def add(self, key):
pass
@property
def count():
pass
def FNVHash(key):
fnv_prime = 0x811C9DC5
hash = 0
for i in range(len(key)):
hash *= fnv_prime
hash ^= ord(key[i])
return hash
def APHash(key):
hash = 0xAAAAAAAA
for i in range(len(key)):
if ((i & 1) == 0):
hash ^= ((hash << 7) ^ ord(key[i]) * (hash >> 3))
else:
hash ^= (~((hash << 11) + ord(key[i]) ^ (hash >> 5)))
return hash
def convert_bytes(bytes):
bytes = float(bytes)
if bytes > :
elif:
elif:
else:
return size