From a551a8a219e9d8ac1ba3bf279c435204af335a57 Mon Sep 17 00:00:00 2001 From: Justin Ethier Date: Fri, 7 May 2021 18:58:58 -0700 Subject: [PATCH] Sync changes --- ck-polyfill.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/ck-polyfill.c b/ck-polyfill.c index e50fc74a..49a6e485 100644 --- a/ck-polyfill.c +++ b/ck-polyfill.c @@ -58,15 +58,18 @@ void *ck_hs_get(ck_hs_t *_hs, unsigned long hash, const void *key) bool ck_hs_put(ck_hs_t *_hs, unsigned long hash, const void *key) { bool result = false; - int rv; + int rv, index; simple_hashset_t hs = (*_hs).hs; pthread_mutex_lock(&((*_hs).lock)); - rv = simple_hashset_add(hs, (symbol_type *)key); - if (rv >= 0) { - result = true; - } + //index = simple_hashset_is_member(hs, (symbol_type *)key); + //if (index == 0) { + rv = simple_hashset_add(hs, (symbol_type *)key); + if (rv >= 0) { + result = true; + } + //} pthread_mutex_unlock(&((*_hs).lock)); return result; @@ -253,11 +256,14 @@ void ck_pr_store_ptr(void *target, void *value) static const size_t prime_1 = 73; static const size_t prime_2 = 5009; -size_t hash_function(const char* p, size_t len) -{ - size_t hash = 0; - for (; *p; ++p) - hash ^= *p + 0x9e3779b9 + (hash << 6) + (hash >> 2); +size_t hash_function(const char* str, size_t len) { + unsigned long hash = 5381; + int c; + + while (c = *str++) { + hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ + } + return hash; }