-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhashfactory.py
More file actions
40 lines (29 loc) · 859 Bytes
/
Copy pathhashfactory.py
File metadata and controls
40 lines (29 loc) · 859 Bytes
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
import random
import hashlib
_memomask = {}
def hash_function(n):
"""
:param n: the index of the hash function
:return: a generated hash function
"""
mask = _memomask.get(n)
if mask is None:
random.seed(n)
mask = _memomask[n] = random.getrandbits(32)
def my_hash(x):
return hash(str(x) + str(n)) ^ mask
return my_hash
def gpu_hash_function(j, rand):
"""
This is a python duplicate of the string hash function used
in gpu_countminsketch.py
:param j: the index of the hash function
:param rand: a list of generated random numbers, must be at least as long as j
:return: a generated hash function
"""
def my_hash(s):
value = rand[j]
for c in s:
value = (((value << 5) + value) + ord(c)) % 2**32
return value
return my_hash