Skip to content

Commit 56f618f

Browse files
committed
Local implementation of murmur2 hash
1 parent 1b6f09a commit 56f618f

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

ipykernel/compiler.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,39 @@
11
from IPython.core.compilerop import CachingCompiler
2-
import murmurhash.mrmr
32
import tempfile
43
import os
54

5+
def murmur2_x86(data, seed):
6+
m = 0x5bd1e995
7+
length = len(data)
8+
h = seed ^ length
9+
rounded_end = (length & 0xfffffffc)
10+
for i in range(0, rounded_end, 4):
11+
k = (ord(data[i]) & 0xff) | ((ord(data[i + 1]) & 0xff) << 8) | \
12+
((ord(data[i + 2]) & 0xff) << 16) | (ord(data[i + 3]) << 24)
13+
k = (k * m) & 0xffffffff
14+
k ^= k >> 24
15+
k = (k * m) & 0xffffffff
16+
17+
h = (h * m) & 0xffffffff
18+
h ^= k
19+
20+
val = length & 0x03
21+
k = 0
22+
if val == 3:
23+
k = (ord(data[rounded_end + 2]) & 0xff) << 16
24+
if val in [2, 3]:
25+
k |= (ord(data[rounded_end + 1]) & 0xff) << 8
26+
if val in [1, 2, 3]:
27+
k |= ord(data[rounded_end]) & 0xff
28+
h ^= k
29+
h = (h * m) & 0xffffffff
30+
31+
h ^= h >> 13
32+
h = (h * m) & 0xffffffff
33+
h ^= h >> 15
34+
35+
return h
36+
637
def get_tmp_directory():
738
tmp_dir = tempfile.gettempdir()
839
pid = os.getpid()
@@ -13,9 +44,7 @@ def get_tmp_hash_seed():
1344
return hash_seed
1445

1546
def get_file_name(code):
16-
name = murmurhash.mrmr.hash(code, seed = get_tmp_hash_seed(), murmur_version=2)
17-
if name < 0:
18-
name += 2**32
47+
name = murmur2_x86(code, get_tmp_hash_seed())
1948
return get_tmp_directory() + '/' + str(name) + '.py'
2049

2150
class XCachingCompiler(CachingCompiler):

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ def run(self):
9595
'jupyter_client',
9696
'tornado>=4.2',
9797
'appnope;platform_system=="Darwin"',
98-
#'murmurhash>=1.0.0' requires https://github.com/explosion/murmurhash/pull/24
9998
],
10099
extras_require={
101100
'test': [

0 commit comments

Comments
 (0)