From 940ac5134d8d0a296b30ef880223a29da91299eb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 17 May 2015 16:11:12 +0100 Subject: [PATCH] Adopt xxhash invocation. --- src/libutil/bloom.c | 2 +- src/libutil/fuzzy.c | 11 ++++++----- src/libutil/uthash_strcase.h | 7 ++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/libutil/bloom.c b/src/libutil/bloom.c index 044cdaa10..c3e8b4c8e 100644 --- a/src/libutil/bloom.c +++ b/src/libutil/bloom.c @@ -116,7 +116,7 @@ rspamd_bloom_add (rspamd_bloom_filter_t * bloom, const gchar *s) } len = strlen (s); for (n = 0; n < bloom->nfuncs; ++n) { - v = XXH32 (s, len, bloom->seeds[n]) % bloom->asize; + v = XXH64 (s, len, bloom->seeds[n]) % bloom->asize; INCBIT (bloom->a, v, t); } diff --git a/src/libutil/fuzzy.c b/src/libutil/fuzzy.c index a15be12e2..218065b77 100644 --- a/src/libutil/fuzzy.c +++ b/src/libutil/fuzzy.c @@ -524,13 +524,14 @@ guint rspamd_fuzzy_hash (gconstpointer key) { rspamd_fuzzy_t *fh = (rspamd_fuzzy_t *)key; - void *st; + XXH64_state_t xxh; - st = XXH32_init (0xdeadbeef); - XXH32_update (st, &fh->block_size, sizeof (fh->block_size)); - XXH32_update (st, fh->hash_pipe, rspamd_fuzzy_len (fh)); + XXH64_reset (&xxh, rspamd_hash_seed ()); - return XXH32_digest (st); + XXH64_update (&xxh, &fh->block_size, sizeof (fh->block_size)); + XXH64_update (&xxh, fh->hash_pipe, rspamd_fuzzy_len (fh)); + + return XXH64_digest (&xxh); } gboolean diff --git a/src/libutil/uthash_strcase.h b/src/libutil/uthash_strcase.h index 4e28f3110..55fae4d7e 100644 --- a/src/libutil/uthash_strcase.h +++ b/src/libutil/uthash_strcase.h @@ -36,13 +36,14 @@ #define HASH_KEYCMP(a,b,len) memcmp(a,b,len) #else #define HASH_FUNCTION(key,keylen,num_bkts,hashv,bkt) do {\ - void *xxh = XXH32_init(0xdead); \ + XXH32_state_t xxh; \ + XXH32_reset(&xxh, 0xdead); \ unsigned char *p = (unsigned char *)key, t; \ for (unsigned int i = 0; i < keylen; i ++) { \ t = g_ascii_tolower(p[i]); \ - XXH32_update(xxh, &t, 1); \ + XXH32_update(&xxh, &t, 1); \ } \ - hashv = XXH32_digest(xxh); \ + hashv = XXH32_digest(&xxh); \ bkt = (hashv) & (num_bkts-1); \ } while (0) #define HASH_KEYCMP(a,b,len) strncasecmp(a,b,len) -- 2.39.5