# HG changeset patch # User Mike Becker # Date 1653652947 -7200 # Node ID 2d6a3e2dc8ff6b0363cd21da5de8edf5b78f3800 # Parent 8603709932b92abfec202d1965888d5437c76f92 fix wrong slot and index numbers diff -r 8603709932b9 -r 2d6a3e2dc8ff src/hash_map.c --- a/src/hash_map.c Fri May 27 14:02:14 2022 +0200 +++ b/src/hash_map.c Fri May 27 14:02:27 2022 +0200 @@ -295,20 +295,15 @@ } else { // just advance elm = elm->next; + iter->index++; } - // do we leave the bucket? - if (elm == NULL) { - // search the next bucket - for (; elm == NULL && iter->slot < map->bucket_count; iter->slot++) { - elm = map->buckets[iter->slot]; - } + // search the next bucket, if required + while (elm == NULL && ++iter->slot < map->bucket_count) { + elm = map->buckets[iter->slot]; } - // advance the index in any case - iter->index++; - - // fill the struct with the current element + // fill the struct with the next element iter->elem_handle = elm; if (elm == NULL) { iter->kv_data.key = NULL; @@ -334,7 +329,7 @@ if (map->size > 0) { struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map; - struct cx_hash_map_element_s *elm = NULL; + struct cx_hash_map_element_s *elm = hash_map->buckets[0]; for (; elm == NULL; iter.slot++) { elm = hash_map->buckets[iter.slot]; }