--- 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]; }