From 3cf7b66cea78599d4dad3022e2c340904d656449 Mon Sep 17 00:00:00 2001 From: Orna Agmon Ben-Yehuda Date: Wed, 21 Nov 2012 09:52:14 +0200 Subject: [PATCH] exporting the hash table size via tell_hashsize --- assoc.c | 24 +++++++++++++++--------- assoc.h | 5 +++++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/assoc.c b/assoc.c index bcaf6f2692..a30dd8afe0 100644 --- a/assoc.c +++ b/assoc.c @@ -24,6 +24,8 @@ #include #include #include +#include "slabs.h" +#include "assoc.h" static pthread_cond_t maintenance_cond = PTHREAD_COND_INITIALIZER; @@ -58,6 +60,10 @@ static bool expanding = false; */ static unsigned int expand_bucket = 0; +int tell_hashsize(void){ + return stats.hash_bytes; +} + void assoc_init(const int hashtable_init) { if (hashtable_init) { hashpower = hashtable_init; @@ -79,9 +85,9 @@ item *assoc_find(const char *key, const size_t nkey, const uint32_t hv) { if (expanding && (oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket) - { - it = old_hashtable[oldbucket]; - } else { + { + it = old_hashtable[oldbucket]; + } else { it = primary_hashtable[hv & hashmask(hashpower)]; } @@ -147,14 +153,14 @@ static void assoc_expand(void) { int assoc_insert(item *it, const uint32_t hv) { unsigned int oldbucket; -// assert(assoc_find(ITEM_key(it), it->nkey) == 0); /* shouldn't have duplicately named things defined */ + // assert(assoc_find(ITEM_key(it), it->nkey) == 0); /* shouldn't have duplicately named things defined */ if (expanding && (oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket) - { - it->h_next = old_hashtable[oldbucket]; - old_hashtable[oldbucket] = it; - } else { + { + it->h_next = old_hashtable[oldbucket]; + old_hashtable[oldbucket] = it; + } else { it->h_next = primary_hashtable[hv & hashmask(hashpower)]; primary_hashtable[hv & hashmask(hashpower)] = it; } @@ -183,7 +189,7 @@ void assoc_delete(const char *key, const size_t nkey, const uint32_t hv) { *before = nxt; return; } - /* Note: we never actually get here. the callers don't delete things + /* Note: we never actually get here. The callers don't delete things they can't find. */ assert(*before != 0); } diff --git a/assoc.h b/assoc.h index ccdfdd5a35..5e1e5ad5b6 100644 --- a/assoc.h +++ b/assoc.h @@ -1,3 +1,5 @@ +#ifndef ASSOC_H +#define ASSOC_H /* associative array */ void assoc_init(const int hashpower_init); item *assoc_find(const char *key, const size_t nkey, const uint32_t hv); @@ -6,4 +8,7 @@ void assoc_delete(const char *key, const size_t nkey, const uint32_t hv); void do_assoc_move_next_bucket(void); int start_assoc_maintenance_thread(void); void stop_assoc_maintenance_thread(void); +/*memory size evaluation*/ +int tell_hashsize(void); +#endif