Python 3 support
This commit is contained in:
parent
13742cb982
commit
f94aa2578d
1 changed files with 57 additions and 24 deletions
81
module.cpp
81
module.cpp
|
|
@ -1,13 +1,35 @@
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include "MurmurHash3.h"
|
#include "MurmurHash3.h"
|
||||||
|
|
||||||
|
static PyObject *hash32(PyObject *, PyObject *);
|
||||||
|
static PyObject *hash128(PyObject *, PyObject *);
|
||||||
|
static PyObject *hash128_64(PyObject *, PyObject *);
|
||||||
|
|
||||||
const char *documentation =
|
const char *documentation =
|
||||||
"Python wrapper around the MurmurHash3 library, written in C++. "
|
"Python wrapper around the MurmurHash3 library, written in C++. "
|
||||||
"Functions included are: hash32, hash128, and hash128_64. All of "
|
"Functions included are: hash32, hash128, and hash128_64. All of "
|
||||||
"these functions take the same parameters, which are: "
|
"these functions take the same parameters, which are: "
|
||||||
"(<str/unicode/buffer>, [seed]), but may return different types.";
|
"(<str/unicode/buffer>, [seed]), but may return different types.";
|
||||||
|
|
||||||
static PyObject* hash32(PyObject *self, PyObject *args)
|
static PyMethodDef methods[] = {
|
||||||
|
{"hash32", hash32, METH_VARARGS,
|
||||||
|
"Calculate Murmur3 32-bit unsigned hash value. "
|
||||||
|
"Parameters: <str>, [seed]"},
|
||||||
|
|
||||||
|
{"hash128", hash128, METH_VARARGS,
|
||||||
|
"Calculate Murmur3 128-bit hash to four 32bit integers. "
|
||||||
|
"Returns tuple (int, int, int, int). "
|
||||||
|
"Parameters: <str>, [seed]"},
|
||||||
|
|
||||||
|
{"hash128_64", hash128_64, METH_VARARGS,
|
||||||
|
"Calculate Murmur3 128-bit hash to two 64bit integers. "
|
||||||
|
"Returns tuple (int, int). "
|
||||||
|
"Parameters: <str>, [seed]"},
|
||||||
|
|
||||||
|
{NULL, NULL, 0, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
|
static PyObject *hash32(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *value = NULL;
|
char *value = NULL;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
|
|
@ -120,27 +142,38 @@ static PyObject *hash128_64(PyObject *self, PyObject *args)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef methods[] = {
|
#if PY_MAJOR_VERSION <= 2
|
||||||
{"hash32", hash32, METH_VARARGS,
|
/* Python 1.x/2.x */
|
||||||
"Calculate Murmur3 32-bit unsigned hash value. "
|
|
||||||
"Parameters: <str>, [seed]"},
|
extern "C"
|
||||||
|
PyMODINIT_FUNC
|
||||||
{"hash128", hash128, METH_VARARGS,
|
initmurmur3(void)
|
||||||
"Calculate Murmur3 128-bit hash to four 32bit integers. "
|
{
|
||||||
"Returns tuple (int, int, int, int). "
|
//Py_Initialize();
|
||||||
"Parameters: <str>, [seed]"},
|
(void) Py_InitModule3("murmur3", methods, (char *)documentation);
|
||||||
|
}
|
||||||
{"hash128_64", hash128_64, METH_VARARGS,
|
#else
|
||||||
"Calculate Murmur3 128-bit hash to two 64bit integers. "
|
/* Python 3.x */
|
||||||
"Returns tuple (int, int). "
|
|
||||||
"Parameters: <str>, [seed]"},
|
|
||||||
|
|
||||||
{NULL, NULL, 0, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
PyMODINIT_FUNC
|
static PyModuleDef murmur3_module = {
|
||||||
initmurmur3(void)
|
PyModuleDef_HEAD_INIT,
|
||||||
{
|
"murmur3",
|
||||||
//Py_Initialize();
|
documentation,
|
||||||
(void) Py_InitModule3("murmur3", methods, (char *)documentation);
|
-1,
|
||||||
}
|
methods,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
extern "C"
|
||||||
|
PyMODINIT_FUNC
|
||||||
|
PyInit_murmur3(void)
|
||||||
|
{
|
||||||
|
PyObject *module;
|
||||||
|
|
||||||
|
module = PyModule_Create(&murmur3_module);
|
||||||
|
return module;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue