ia64/xen-unstable

changeset 9134:1c46091df7ce

Avoid floating point in hash table implementation.

Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri Mar 03 19:06:50 2006 +0100 (2006-03-03)
parents 621d32a54e2d
children aefc75f5db5e
files tools/xenstore/hashtable.c
line diff
     1.1 --- a/tools/xenstore/hashtable.c	Fri Mar 03 18:26:41 2006 +0100
     1.2 +++ b/tools/xenstore/hashtable.c	Fri Mar 03 19:06:50 2006 +0100
     1.3 @@ -6,6 +6,7 @@
     1.4  #include <stdio.h>
     1.5  #include <string.h>
     1.6  #include <math.h>
     1.7 +#include <stdint.h>
     1.8  
     1.9  /*
    1.10  Credit for primes table: Aaron Krowne
    1.11 @@ -22,7 +23,7 @@ 50331653, 100663319, 201326611, 40265318
    1.12  805306457, 1610612741
    1.13  };
    1.14  const unsigned int prime_table_length = sizeof(primes)/sizeof(primes[0]);
    1.15 -const float max_load_factor = 0.65;
    1.16 +const unsigned int max_load_factor = 65; /* percentage */
    1.17  
    1.18  /*****************************************************************************/
    1.19  struct hashtable *
    1.20 @@ -48,7 +49,7 @@ create_hashtable(unsigned int minsize,
    1.21      h->entrycount   = 0;
    1.22      h->hashfn       = hashf;
    1.23      h->eqfn         = eqf;
    1.24 -    h->loadlimit    = (unsigned int) ceil(size * max_load_factor);
    1.25 +    h->loadlimit    = (unsigned int)(((uint64_t)size * max_load_factor) / 100);
    1.26      return h;
    1.27  }
    1.28  
    1.29 @@ -121,7 +122,8 @@ hashtable_expand(struct hashtable *h)
    1.30          }
    1.31      }
    1.32      h->tablelength = newsize;
    1.33 -    h->loadlimit   = (unsigned int) ceil(newsize * max_load_factor);
    1.34 +    h->loadlimit   = (unsigned int)
    1.35 +        (((uint64_t)newsize * max_load_factor) / 100);
    1.36      return -1;
    1.37  }
    1.38