[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] Avoid floating point in hash table implementation.



# HG changeset patch
# User kaf24@xxxxxxxxxxxxxxxxxxxx
# Node ID 1c46091df7ce2d55f003cef8bde6efa4a41dd8bd
# Parent  621d32a54e2d143f0b059997a2f438121bae1d5a
Avoid floating point in hash table implementation.

Signed-off-by: Keir Fraser <keir@xxxxxxxxxxxxx>

diff -r 621d32a54e2d -r 1c46091df7ce tools/xenstore/hashtable.c
--- a/tools/xenstore/hashtable.c        Fri Mar  3 17:26:41 2006
+++ b/tools/xenstore/hashtable.c        Fri Mar  3 18:06:50 2006
@@ -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 @@
 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 @@
     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 @@
         }
     }
     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;
 }
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.