自己写一个python的fnv哈希的扩展,文件名fnv_module.c #include <Python.h> #include <sys/types.h> /* typedef unsigned long fnv_t; */ typedef u_int32_t fnv_t; static fnv_t FNVHash(char* data, size_t n) { unsigned char *s = (unsigned char*)data; fnv_t hash = 2166136261UL; while(*s) { hash *= 16777619; hash %= 0xFFFFFFFF; hash ^= (fnv_t)*s++; } return hash; } PyObject* fnvhash(PyObject *self, PyObject *args) { int hash; char *s; PyObject* pInt; if(!PyArg_ParseTuple(args, "s", &s)) return NULL; hash = FNVHash(s, strlen(s)); /* pInt = Py_BuildValue("i", hash); */ pInt = PyLong_FromUnsignedLong(hash); return pInt; } static PyMethodDef fnv_hash_methods[] = { {"fnvhash", fnvhash, METH_VARARGS, "Caculate FNV-32 hash!"}, {NULL, NULL} }; void initfnv()