Skip to content

Commit

Permalink
exporting the hash table size via tell_hashsize
Browse files Browse the repository at this point in the history
  • Loading branch information
ladypine committed Nov 21, 2012
1 parent b29b87d commit 3cf7b66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
24 changes: 15 additions & 9 deletions assoc.c
Expand Up @@ -24,6 +24,8 @@
#include <string.h> #include <string.h>
#include <assert.h> #include <assert.h>
#include <pthread.h> #include <pthread.h>
#include "slabs.h"
#include "assoc.h"


static pthread_cond_t maintenance_cond = PTHREAD_COND_INITIALIZER; static pthread_cond_t maintenance_cond = PTHREAD_COND_INITIALIZER;


Expand Down Expand Up @@ -58,6 +60,10 @@ static bool expanding = false;
*/ */
static unsigned int expand_bucket = 0; static unsigned int expand_bucket = 0;


int tell_hashsize(void){
return stats.hash_bytes;
}

void assoc_init(const int hashtable_init) { void assoc_init(const int hashtable_init) {
if (hashtable_init) { if (hashtable_init) {
hashpower = hashtable_init; hashpower = hashtable_init;
Expand All @@ -79,9 +85,9 @@ item *assoc_find(const char *key, const size_t nkey, const uint32_t hv) {


if (expanding && if (expanding &&
(oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket) (oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket)
{ {
it = old_hashtable[oldbucket]; it = old_hashtable[oldbucket];
} else { } else {
it = primary_hashtable[hv & hashmask(hashpower)]; it = primary_hashtable[hv & hashmask(hashpower)];
} }


Expand Down Expand Up @@ -147,14 +153,14 @@ static void assoc_expand(void) {
int assoc_insert(item *it, const uint32_t hv) { int assoc_insert(item *it, const uint32_t hv) {
unsigned int oldbucket; 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 && if (expanding &&
(oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket) (oldbucket = (hv & hashmask(hashpower - 1))) >= expand_bucket)
{ {
it->h_next = old_hashtable[oldbucket]; it->h_next = old_hashtable[oldbucket];
old_hashtable[oldbucket] = it; old_hashtable[oldbucket] = it;
} else { } else {
it->h_next = primary_hashtable[hv & hashmask(hashpower)]; it->h_next = primary_hashtable[hv & hashmask(hashpower)];
primary_hashtable[hv & hashmask(hashpower)] = it; primary_hashtable[hv & hashmask(hashpower)] = it;
} }
Expand Down Expand Up @@ -183,7 +189,7 @@ void assoc_delete(const char *key, const size_t nkey, const uint32_t hv) {
*before = nxt; *before = nxt;
return; 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. */ they can't find. */
assert(*before != 0); assert(*before != 0);
} }
Expand Down
5 changes: 5 additions & 0 deletions assoc.h
@@ -1,3 +1,5 @@
#ifndef ASSOC_H
#define ASSOC_H
/* associative array */ /* associative array */
void assoc_init(const int hashpower_init); void assoc_init(const int hashpower_init);
item *assoc_find(const char *key, const size_t nkey, const uint32_t hv); item *assoc_find(const char *key, const size_t nkey, const uint32_t hv);
Expand All @@ -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); void do_assoc_move_next_bucket(void);
int start_assoc_maintenance_thread(void); int start_assoc_maintenance_thread(void);
void stop_assoc_maintenance_thread(void); void stop_assoc_maintenance_thread(void);
/*memory size evaluation*/
int tell_hashsize(void);
#endif


0 comments on commit 3cf7b66

Please sign in to comment.