Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes for OSX; upstream r136; 2.4 support.

 * Ensure that 'ppc' platform is not built on OSX i386/x86_64 machines.
   Avoid compiling Platform.cpp as SetAffinity is not used.
 * Synced with upstream r136. None of the changes affect this extension.
 * Now builds for Python version 2.4.  Tested versions 2.4 through 3.1.
 * Unified test case.
 * Added quick usage example to the README.
 * Bumped version to 0.136.1.
 * Extension and project version numbers now match.

Thanks to @jbenet for the initial commit on which this is based.
  • Loading branch information...
commit 96d8b9bd3ec049a38ef38777fa97f65bae8ead85 1 parent 7da2395
@phensley authored
View
12 README.md
@@ -6,5 +6,17 @@ variants.
License: MIT License
+Usage
+-----
+ >>> import smhasher
+ >>> [k for k in dir(smhasher) if k[0] == 'm']
+ ['murmur3_x64_128', 'murmur3_x64_64', 'murmur3_x86_128', 'murmur3_x86_64']
+
+ >>> smhasher.murmur3_x86_128('hello')
+ 213030289162235495270783145757721615258L
+
+ >>> seed = 1138
+ >>> smhasher.murmur3_x86_128('hello', seed)
+ 94758481705480737162820094006203962724L
View
17 setup.py
@@ -1,22 +1,31 @@
+import os
+import platform
+import sys
from distutils.core import setup, Extension
# version number is x.[upstream svn revision].release until upstream
# creates a formal version number.
-VERSION = '0.135.4'
+VERSION = '0.136.1'
+
+# avoid building universal binary (ppc) on osx non-ppc platforms
+if sys.platform == 'darwin':
+ arch = platform.machine()
+ if arch in ('i386', 'x86_64'):
+ os.environ['ARCHFLAGS'] = '-arch i386 -arch x86_64'
smhasher_ext = Extension('smhasher',
sources=[
'smhasher.cpp',
'smhasher/MurmurHash3.cpp',
- 'smhasher/Platform.cpp'
- ],
+ ],
include_dirs=['smhasher'],
define_macros=[('MODULE_VERSION', '"%s"' % VERSION)])
+
setup(
name='smhasher',
- version=0.1,
+ version=VERSION,
description='Python extension for smhasher hash functions',
ext_modules=[smhasher_ext]
)
View
7 smhasher.cpp
@@ -12,6 +12,13 @@
#include "MurmurHash3.h"
+#if PY_VERSION_HEX < 0x02050000
+typedef int Py_ssize_t;
+#define PY_SSIZE_T_MAX INT_MAX
+#define PY_SSIZE_T_MIN INT_MIN
+#endif
+
+
static PyObject *
_py_murmur3_128(PyObject *self, PyObject *args, int x86, int size)
{
View
2  smhasher/MurmurHash3.cpp
@@ -132,7 +132,7 @@ void MurmurHash3_x86_32 ( const void * key, int len,
case 3: k1 ^= tail[2] << 16;
case 2: k1 ^= tail[1] << 8;
case 1: k1 ^= tail[0];
- k1 *= c1; k1 = ROTL32(k1,16); k1 *= c2; h1 ^= k1;
+ k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
};
//----------
View
2  smhasher/main.cpp
@@ -69,7 +69,7 @@ HashInfo g_hashes[] =
// MurmurHash3
- { MurmurHash3_x86_32, 32, 0x3252D141, "Murmur3A", "MurmurHash3 for x86, 32-bit" },
+ { MurmurHash3_x86_32, 32, 0xB0F57EE3, "Murmur3A", "MurmurHash3 for x86, 32-bit" },
{ MurmurHash3_x86_128, 128, 0xB3ECE62A, "Murmur3C", "MurmurHash3 for x86, 128-bit" },
{ MurmurHash3_x64_128, 128, 0x6384BA69, "Murmur3F", "MurmurHash3 for x64, 128-bit" },
View
0  test_3x.py → smhasher_test.py
File renamed without changes
View
32 test_2x.py
@@ -1,32 +0,0 @@
-
-import smhasher
-import timeit
-
-print 'smhasher version: %s\n\n' % smhasher.__version__
-
-def demo(name, seed=None):
- text = 'samplebias'
- func = getattr(smhasher, name)
- msg = name
- if seed:
- msg += ' seed: %d' % seed
- res = func(text, seed)
- else:
- res = func(text)
- print '%s\n %d\n %s\n' % (msg, res, hex(res))
-
-demo('murmur3_x86_64')
-demo('murmur3_x86_64', 123)
-
-demo('murmur3_x86_128')
-demo('murmur3_x64_128')
-demo('murmur3_x86_128', 123456789)
-
-
-# timing comparison with str __hash__
-t = timeit.Timer("smhasher.murmur3_x86_64('hello')", "import smhasher")
-print 'smhasher.murmur3:', t.timeit()
-
-t = timeit.Timer("str.__hash__('hello')")
-print ' str.__hash__:', t.timeit()
-
Please sign in to comment.
Something went wrong with that request. Please try again.