diff options
author | Rainer Gerhards <rgerhards@adiscon.com> | 2010-10-11 17:11:00 +0200 |
---|---|---|
committer | Rainer Gerhards <rgerhards@adiscon.com> | 2010-10-11 17:11:00 +0200 |
commit | 8c3d40b798e3ed68fb03629d87b55140cb6bc044 (patch) | |
tree | b6320896b01d58c083e82a0b5c22e13240dcc6f2 /runtime | |
parent | ed324a9a610f91f54514eb713ff5593bde1012e6 (diff) | |
download | rsyslog-8c3d40b798e3ed68fb03629d87b55140cb6bc044.tar.gz rsyslog-8c3d40b798e3ed68fb03629d87b55140cb6bc044.tar.xz rsyslog-8c3d40b798e3ed68fb03629d87b55140cb6bc044.zip |
removed need for math library
by doing math a little bit more optimal in hash table code. Also reduced
memory requirement for imuxsock hash tables (expected number of connections
was set too high -- table can be extended dynamically).
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/hashtable.c | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/runtime/hashtable.c b/runtime/hashtable.c index 41fc60fe..a01fa7d9 100644 --- a/runtime/hashtable.c +++ b/runtime/hashtable.c @@ -23,7 +23,17 @@ 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; + +#define MAX_LOAD_FACTOR 65 /* to get real factor, divide by 100! */ + +/* compute max load. We use a constant factor of 0.65, but do + * everything times 100, so that we do not need floats. + */ +static inline unsigned +getLoadLimit(unsigned size) +{ + return (unsigned int) ((unsigned long long) size * MAX_LOAD_FACTOR) / 100; +} /*****************************************************************************/ struct hashtable * @@ -50,7 +60,7 @@ create_hashtable(unsigned int minsize, h->hashfn = hashf; h->eqfn = eqf; h->dest = dest; - h->loadlimit = (unsigned int) ceil(size * max_load_factor); + h->loadlimit = getLoadLimit(size); return h; } @@ -123,7 +133,7 @@ hashtable_expand(struct hashtable *h) } } h->tablelength = newsize; - h->loadlimit = (unsigned int) ceil(newsize * max_load_factor); + h->loadlimit = getLoadLimit(newsize); return -1; } |