77
88#include "khashl.h"
99#include "ulib.h"
10+ #include <stdint.h>
1011
11- #define klib_hash_int (x ) ((khint_t)(x))
12- UHASH_INIT (uint , ulib_uint , UHASH_VAL_IGNORE , ulib_hash_int , ulib_eq )
13- KHASHL_SET_INIT (KH_LOCAL , kh_uint_t , kh_uint , ulib_uint , klib_hash_int , ulib_eq )
12+ UHASH_INIT (uint , uint32_t , UHASH_VAL_IGNORE , ulib_hash_int32 , ulib_eq )
13+ KHASHL_SET_INIT (KH_LOCAL , kh_uint_t , kh_uint , uint32_t , kh_hash_uint32 , ulib_eq )
1414
1515enum {
1616 SEED = 31 ,
@@ -26,9 +26,9 @@ typedef struct HashTable {
2626 char const * name ;
2727 void * (* init )(void );
2828 void (* deinit )(void * );
29- bool (* insert )(void * , ulib_uint );
30- bool (* contains )(void * , ulib_uint );
31- bool (* remove )(void * , ulib_uint );
29+ bool (* insert )(void * , uint32_t );
30+ bool (* contains )(void * , uint32_t );
31+ bool (* remove )(void * , uint32_t );
3232} HashTable ;
3333
3434// UHash
@@ -44,15 +44,15 @@ static void bench_uhash_deinit(void *h) {
4444 ulib_free (h );
4545}
4646
47- static bool bench_uhash_insert (void * h , ulib_uint key ) {
47+ static bool bench_uhash_insert (void * h , uint32_t key ) {
4848 return uhset_insert (uint , h , key );
4949}
5050
51- static bool bench_uhash_contains (void * h , ulib_uint key ) {
51+ static bool bench_uhash_contains (void * h , uint32_t key ) {
5252 return uhash_contains (uint , h , key );
5353}
5454
55- static bool bench_uhash_remove (void * h , ulib_uint key ) {
55+ static bool bench_uhash_remove (void * h , uint32_t key ) {
5656 return uhset_remove (uint , h , key );
5757}
5858
@@ -77,18 +77,18 @@ static void bench_khashl_deinit(void *h) {
7777 kh_uint_destroy (h );
7878}
7979
80- static bool bench_khashl_insert (void * h , ulib_uint key ) {
80+ static bool bench_khashl_insert (void * h , uint32_t key ) {
8181 int ret ;
8282 kh_uint_put (h , key , & ret );
8383 return !!ret ;
8484}
8585
86- static bool bench_khashl_contains (void * h , ulib_uint key ) {
86+ static bool bench_khashl_contains (void * h , uint32_t key ) {
8787 kh_uint_t * ht = h ;
8888 return kh_uint_get (ht , key ) != kh_end (ht );
8989}
9090
91- static bool bench_khashl_remove (void * h , ulib_uint key ) {
91+ static bool bench_khashl_remove (void * h , uint32_t key ) {
9292 kh_uint_t * ht = h ;
9393 khint_t i = kh_uint_get (ht , key );
9494 if (i != kh_end (ht )) {
@@ -120,7 +120,7 @@ static void bench_hash(HashTable *table, ulib_uint size) {
120120 ulib_uint count = 0 ;
121121 ulog_perf ("insert" ) {
122122 for (ulib_uint i = 0 ; i < size ; ++ i ) {
123- ulib_uint key = urand_range (0 , size >> 1 );
123+ uint32_t key = ( uint32_t ) urand_range (0 , size >> 1 );
124124 if (table -> insert (h , key )) count ++ ;
125125 }
126126 }
@@ -129,15 +129,15 @@ static void bench_hash(HashTable *table, ulib_uint size) {
129129 count = 0 ;
130130 ulog_perf ("get" ) {
131131 for (ulib_uint i = 0 ; i < size ; ++ i ) {
132- ulib_uint key = urand_range (0 , size >> 1 );
132+ uint32_t key = ( uint32_t ) urand_range (0 , size >> 1 );
133133 if (table -> contains (h , key )) count ++ ;
134134 }
135135 }
136136 ulog_debug ("Found: %" ULIB_UINT_FMT , count );
137137
138138 ulog_perf ("remove" ) {
139139 for (ulib_uint i = 0 ; i < size ; ++ i ) {
140- ulib_uint key = urand_range (0 , size >> 1 );
140+ uint32_t key = ( uint32_t ) urand_range (0 , size >> 1 );
141141 if (table -> remove (h , key )) count ++ ;
142142 }
143143 }
0 commit comments