Avoid floating point in hash table implementation.

Signed-off-by: Keir Fraser <keir@xensource.com>
This commit is contained in:
kaf24@firebug.cl.cam.ac.uk committed 2006-03-03 19:06:50 +01:00
1 parent d870b4b709
commit 74bb865dac
1 file changed
+5 -3
+5 -3
View File
@@ -6,6 +6,7 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdint.h>
/*
Credit for primes table: Aaron Krowne
@@ -22,7 +23,7 @@ static const unsigned int primes[] = {
805306457, 1610612741
};
const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
const float max_load_factor = 0.65;
const unsigned int max_load_factor = 65; /* percentage */
/*****************************************************************************/
struct hashtable *
@@ -48,7 +49,7 @@ create_hashtable(unsigned int minsize,
h->entrycount = 0;
h->hashfn = hashf;
h->eqfn = eqf;
h->loadlimit = (unsigned int) ceil(size * max_load_factor);
h->loadlimit = (unsigned int)(((uint64_t)size * max_load_factor) / 100);
return h;
}
@@ -121,7 +122,8 @@ hashtable_expand(struct hashtable *h)
}
}
h->tablelength = newsize;
h->loadlimit = (unsigned int) ceil(newsize * max_load_factor);
h->loadlimit = (unsigned int)
(((uint64_t)newsize * max_load_factor) / 100);
return -1;
}
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.