summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/common-utils.c
diff options
context:
space:
mode:
authorKotresh HR <khiremat@redhat.com>2017-06-28 05:09:12 -0400
committerNiels de Vos <ndevos@redhat.com>2017-06-30 08:16:57 +0000
commit292b4e42fdc023e307fde35e189285040d4b9cdd (patch)
tree1c91585e4a9c4bd3871666622f8fe5f158c67ec0 /libglusterfs/src/common-utils.c
parentd95535bae2d200c2210feac7568b1fdbf6f545a9 (diff)
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 <khiremat@redhat.com> Reviewed-on: https://review.gluster.org/17641 Smoke: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Amar Tumballi <amarts@redhat.com> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> Reviewed-by: Niels de Vos <ndevos@redhat.com>
Diffstat (limited to 'libglusterfs/src/common-utils.c')
-rw-r--r--libglusterfs/src/common-utils.c18
1 files changed, 18 insertions, 0 deletions
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 <ifaddrs.h>
#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