Python/Cython Murmurhash3 Binding.
yammh3的Python项目详细描述
又一个杂音3绑定
python/cython杂音3绑定。
- 自由软件:麻省理工学院许可证
- 文档:https://yammh3.readthedocs.org。
功能
- 提供高级python api。
- 提供低水平的cython绑定。
- Python2和3支持。
示例
下面是python中的一个示例:
fromyammh3importhash64key=b"yammh3!"# hash* functions return a signed integer by default.print("signed 64 bits hash is %s"%hash64(key))# -> -1339990020854215562print("unsigned 64 bits hash is %s"%hash64(key,signed=False))# -> 17106754052855336054L
在cython中,首先我们需要用代码编写一个.pyx文件:
# file: yammh3_example.pyx# mhash* functions are only available via cimport.fromyammh3._yammh3cimportmhash64,mhash64sfromyammh3._yammh3cimportint64_t,uint64_t,uint32_tdefprint_hashes(byteskey):cdefuint64_th1cdefint64_th2cdefuint32_tn=len(key)cdefchar *c_key=<char*>keywithnogil:# releasing the GIL!h1=mhash64(c_key,n)h2=mhash64s(c_key,n)print("unsigned 64 bits hash is %d"%h1)print("signed 64 bits hash is %d"%h2)
我们需要将其编译为一个模块,通常使用设置脚本:
# file: setup.pyfromsetuptoolsimportsetupfromsetuptools.extensionimportExtensionfromCython.Buildimportcythonizeimportyammh3# already installedsetup(name='yammh3-example',ext_modules=cythonize([Extension('*',['*.pyx'],include_dirs=[yammh3.get_include()]),]))
然后我们将模块构建到位:
$ python setup.py build_ext --inplace Running build_ext building 'yammh3_example' extension ... [snip] ... copying build/lib.macosx-10.5-x86_64-2.7/yammh3_example.so ->
现在我们可以运行代码了:
$ python -c 'import yammh3_example; yammh3_example.print_hashes(b"yammh3!")' unsigned 64 bits hash is 17106754052855336054 signed 64 bits hash is -1339990020854215562
历史记录
0.1.1(2016-06-23)
- 第一个可用版本:)
0.1.0(2016-06-17)
- pypi上的第一个版本。