3434#include "memdbg.h"
3535
3636struct hash *
37- hash_init (const int n_buckets , const uint32_t iv ,
37+ hash_init (const uint32_t n_buckets , const uint32_t iv ,
3838 uint32_t (* hash_function )(const void * key , uint32_t iv ),
3939 bool (* compare_function )(const void * key1 , const void * key2 ))
4040{
4141 struct hash * h ;
42- int i ;
4342
4443 ASSERT (n_buckets > 0 );
4544 ALLOC_OBJ_CLEAR (h , struct hash );
46- h -> n_buckets = (int )adjust_power_of_2 (n_buckets );
45+ h -> n_buckets = (uint32_t )adjust_power_of_2 (n_buckets );
4746 h -> mask = h -> n_buckets - 1 ;
4847 h -> hash_function = hash_function ;
4948 h -> compare_function = compare_function ;
5049 h -> iv = iv ;
5150 ALLOC_ARRAY (h -> buckets , struct hash_bucket , h -> n_buckets );
52- for (i = 0 ; i < h -> n_buckets ; ++ i )
51+ for (uint32_t i = 0 ; i < h -> n_buckets ; ++ i )
5352 {
5453 struct hash_bucket * b = & h -> buckets [i ];
5554 b -> list = NULL ;
@@ -60,8 +59,7 @@ hash_init(const int n_buckets, const uint32_t iv,
6059void
6160hash_free (struct hash * hash )
6261{
63- int i ;
64- for (i = 0 ; i < hash -> n_buckets ; ++ i )
62+ for (uint32_t i = 0 ; i < hash -> n_buckets ; ++ i )
6563 {
6664 struct hash_bucket * b = & hash -> buckets [i ];
6765 struct hash_element * he = b -> list ;
@@ -212,15 +210,15 @@ hash_remove_marked(struct hash *hash, struct hash_bucket *bucket)
212210}
213211
214212void
215- hash_iterator_init_range (struct hash * hash , struct hash_iterator * hi , int start_bucket ,
216- int end_bucket )
213+ hash_iterator_init_range (struct hash * hash , struct hash_iterator * hi , uint32_t start_bucket ,
214+ uint32_t end_bucket )
217215{
218216 if (end_bucket > hash -> n_buckets )
219217 {
220218 end_bucket = hash -> n_buckets ;
221219 }
222220
223- ASSERT (start_bucket >= 0 && start_bucket <= end_bucket );
221+ ASSERT (start_bucket <= end_bucket );
224222
225223 hi -> hash = hash ;
226224 hi -> elem = NULL ;
@@ -325,6 +323,9 @@ hash_iterator_delete_element(struct hash_iterator *hi)
325323 * the return value. Every 1-bit and 2-bit delta achieves avalanche.
326324 * About 36+6len instructions.
327325 *
326+ * #define hashsize(n) ((uint32_t)1<<(n))
327+ * #define hashmask(n) (hashsize(n)-1)
328+ *
328329 * The best hash table sizes are powers of 2. There is no need to do
329330 * mod a prime (mod is sooo slow!). If you need less than 32 bits,
330331 * use a bitmask. For example, if you need only 10 bits, do
0 commit comments