From 292b4e42fdc023e307fde35e189285040d4b9cdd Mon Sep 17 00:00:00 2001 From: Kotresh HR Date: Wed, 28 Jun 2017 05:09:12 -0400 Subject: contrib/xxhash: Add xxhash library xxhash is a faster non-cryptographic hash. https://github.com/Cyan4973/xxHash Release Taken: "xxHash v0.6.2" -------------- Files added: contrib/xxhash/xxhash.c contrib/xxhash/xxhash.h contrib/xxhash/xxhsum.c Modifications to source: ------------------------ Following functions and data types got 'GF_' prefix as below to avoid any form of name collisions in future. ---- Functions ---- GF_XXH_versionNumber GF_XXH32 GF_XXH32_createState GF_XXH32_freeState GF_XXH32_copyState GF_XXH32_reset GF_XXH32_update GF_XXH32_digest GF_XXH32_canonicalFromHash GF_XXH32_hashFromCanonical GF_XXH64 GF_XXH64_createState GF_XXH64_freeState GF_XXH64_copyState GF_XXH64_reset GF_XXH64_update GF_XXH64_digest GF_XXH64_canonicalFromHash GF_XXH64_hashFromCanonical ---- Data Types ---- GF_XXH_errorcode GF_XXH32_state_t* GF_XXH32_canonical_t* GF_XXH32_hash_t GF_XXH64_state_t* GF_XXH64_canonical_t* GF_XXH64_hash_t It is linked with libglusterfs.so. A wrapper funtion is also added for the easy usage in common-utils.c. xxhash can be used for the all the usecases where a faster non-cryptographic hash is required. gfid to path infra would be using this for now. NOTE: ---- The gluster coding guidelines check is ignored as maintaining it further would be difficult. Updates: #253 Change-Id: Ib143f90d91d4ee99864a10246d5983e92900173b Signed-off-by: Kotresh HR Reviewed-on: https://review.gluster.org/17641 Smoke: Gluster Build System Reviewed-by: Amar Tumballi CentOS-regression: Gluster Build System NetBSD-regression: NetBSD Build System Reviewed-by: Niels de Vos --- libglusterfs/src/common-utils.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libglusterfs/src/common-utils.c') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 65557fefba2..5015d9666b6 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -49,6 +49,7 @@ #include "lkowner.h" #include "syscall.h" #include "cli1-xdr.h" +#include "xxhash.h" #include #include "libglusterfs-messages.h" @@ -82,6 +83,23 @@ md5_wrapper(const unsigned char *data, size_t len, char *md5) snprintf(md5 + i * 2, lim-i*2, "%02x", scratch[i]); } +void +gf_xxh64_wrapper(const unsigned char *data, size_t len, unsigned long long seed, + char *xxh64) +{ + unsigned short i = 0; + unsigned short lim = GF_XXH64_DIGEST_LENGTH*2+1; + GF_XXH64_hash_t hash = 0; + GF_XXH64_canonical_t c_hash = {{0,},}; + const uint8_t *p = (const uint8_t *) &c_hash; + + hash = GF_XXH64(data, len, seed); + GF_XXH64_canonicalFromHash(&c_hash, hash); + + for (i = 0; i < GF_XXH64_DIGEST_LENGTH; i++) + snprintf(xxh64 + i * 2, lim-i*2, "%02x", p[i]); +} + /* works similar to mkdir(1) -p. */ int -- cgit