unsigned int XXH32 (const void* input, size_t len, unsigned seed) { #if 0 // Simple version, good for code maintenance, but unfortunately slow for small inputs XXH32_state_t state; XXH32_reset(&state, seed); XXH32_update(&state, input, len); return XXH32_digest(&state); #else XXH_endianess endian_detected = (XXH_endianess)XXH_CPU_LITTLE_ENDIAN; # if !defined(XXH_USE_UNALIGNED_ACCESS) if ((((size_t)input) & 3) == 0) // Input is aligned, let's leverage the speed advantage { if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_aligned); else return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_aligned); } # endif if ((endian_detected==XXH_littleEndian) || XXH_FORCE_NATIVE_FORMAT) return XXH32_endian_align(input, len, seed, XXH_littleEndian, XXH_unaligned); else return XXH32_endian_align(input, len, seed, XXH_bigEndian, XXH_unaligned); #endif }
static uint32_t src_hash(void *_k) { srckey *k = (srckey *)_k; XXH32_state_t h; /* seed is an arbitrary, but fixed value */ XXH32_reset(&h, 42); XXH32_update(&h, (void *)k->src, k->len); XXH32_update(&h, (void *)k->arch, sizeof(k->arch)); return XXH32_digest(&h); }
static void fill_xxhash(struct verify_header *hdr, void *p, unsigned int len) { struct vhdr_xxhash *vh = hdr_priv(hdr); void *state; state = XXH32_init(1); XXH32_update(state, p, len); vh->hash = XXH32_digest(state); }
static uint64_t t_xxhash(void) { void *state; struct timeval s; uint64_t ret; void *buf; int i; state = XXH32_init(0x8989); buf = malloc(CHUNK); randomize_buf(buf, CHUNK, 0x8989); fio_gettime(&s, NULL); for (i = 0; i < NR_CHUNKS; i++) XXH32_update(state, buf, CHUNK); XXH32_digest(state); ret = utime_since_now(&s); free(buf); return ret; }
static int verify_io_u_xxhash(struct verify_header *hdr, struct vcont *vc) { void *p = io_u_verify_off(hdr, vc); struct vhdr_xxhash *vh = hdr_priv(hdr); uint32_t hash; void *state; dprint(FD_VERIFY, "xxhash verify io_u %p, len %u\n", vc->io_u, hdr->len); state = XXH32_init(1); XXH32_update(state, p, hdr->len - hdr_size(vc->td, hdr)); hash = XXH32_digest(state); if (vh->hash == hash) return 0; vc->name = "xxhash"; vc->good_crc = &vh->hash; vc->bad_crc = &hash; vc->crc_len = sizeof(hash); log_verify_failure(hdr, vc); return EILSEQ; }
static PyObject * pyhashxx_hashxx(PyObject* self, PyObject *args, PyObject *kwds) { unsigned int seed = 0; const char* err_msg = NULL; PyObject* err_obj = NULL; Py_ssize_t args_len = 0; unsigned int digest = 0; void* state = NULL; if (kwds != NULL) { Py_ssize_t kwds_size = PyDict_Size(kwds); PyObject* seed_obj = PyDict_GetItemString(kwds, "seed"); if (kwds_size > 1) { err_msg = "Unexpected keyword arguments, only 'seed' is supported."; goto badarg; } if (kwds_size == 1) { if (seed_obj == NULL) { err_msg = "Unexpected keyword argument, only 'seed' is supported."; goto badarg; } #if PY_MAJOR_VERSION < 3 if (PyInt_Check(seed_obj)) seed = PyInt_AsLong(seed_obj); else #endif if (PyLong_Check(seed_obj)) seed = PyLong_AsLong(seed_obj); else { err_msg = "Unexpected seed value type: %S"; err_obj = seed_obj; goto badseed; } } } args_len = PyTuple_GET_SIZE(args); if (args_len == 0) { err_msg = "Received no arguments to be hashed."; goto badarg; } // If possible, use the shorter, faster version that elides // allocating the state variable because it knows there is only // one input. if (args_len == 1) { PyObject* hash_obj = PyTuple_GetItem(args, 0); int did_hash = 1; #if PY_MAJOR_VERSION >= 3 if (PyBytes_Check(hash_obj)) { digest = XXH32(PyBytes_AsString(hash_obj), PyBytes_Size(hash_obj), seed); } #else if (PyString_Check(hash_obj)) { digest = XXH32(PyString_AsString(hash_obj), PyString_Size(hash_obj), seed); } #endif else if (PyByteArray_Check(hash_obj)) { digest = XXH32(PyByteArray_AsString(hash_obj), PyByteArray_Size(hash_obj), seed); } else if (hash_obj == Py_None) { // Nothing to hash digest = XXH32("", 0, seed); } else { did_hash = 0; } if (did_hash) return Py_BuildValue("I", digest); } // Otherwise, do it the long, slower way state = XXH32_init(seed); if (_update_hash(state, args) == NULL) { XXH32_destroy(state); return NULL; } digest = XXH32_digest(state); XXH32_destroy(state); return Py_BuildValue("I", digest); badarg: PyErr_SetString(PyExc_TypeError, err_msg); return NULL; badseed: PyErr_Format(PyExc_TypeError, err_msg, Py_TYPE(err_obj)); return NULL; }
static PyObject * Hashxx_digest(HashxxObject* self) { unsigned int digest = XXH32_digest(self->xxhash_state); return Py_BuildValue("I", digest); }
int xxHashStream::Finish() { Flush(); return XXH32_digest((XXH32_state_t *)context); }
/* * Class: net_jpountz_xxhash_XXHashJNI * Method: XXH32_digest * Signature: (J)I */ JNIEXPORT jint JNICALL Java_net_jpountz_xxhash_XXHashJNI_XXH32_1digest (JNIEnv *env, jclass cls, jlong state) { return XXH32_digest((XXH32_state_t*) state); }