fix wrong slot and index numbers

Fri, 27 May 2022 14:02:27 +0200

author
Mike Becker <universe@uap-core.de>
date
Fri, 27 May 2022 14:02:27 +0200
changeset 560
2d6a3e2dc8ff
parent 559
8603709932b9
child 561
bb17790af41e

fix wrong slot and index numbers

src/hash_map.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/hash_map.c	Fri May 27 14:02:14 2022 +0200
     1.2 +++ b/src/hash_map.c	Fri May 27 14:02:27 2022 +0200
     1.3 @@ -295,20 +295,15 @@
     1.4      } else {
     1.5          // just advance
     1.6          elm = elm->next;
     1.7 +        iter->index++;
     1.8      }
     1.9  
    1.10 -    // do we leave the bucket?
    1.11 -    if (elm == NULL) {
    1.12 -        // search the next bucket
    1.13 -        for (; elm == NULL && iter->slot < map->bucket_count; iter->slot++) {
    1.14 -            elm = map->buckets[iter->slot];
    1.15 -        }
    1.16 +    // search the next bucket, if required
    1.17 +    while (elm == NULL && ++iter->slot < map->bucket_count) {
    1.18 +        elm = map->buckets[iter->slot];
    1.19      }
    1.20  
    1.21 -    // advance the index in any case
    1.22 -    iter->index++;
    1.23 -
    1.24 -    // fill the struct with the current element
    1.25 +    // fill the struct with the next element
    1.26      iter->elem_handle = elm;
    1.27      if (elm == NULL) {
    1.28          iter->kv_data.key = NULL;
    1.29 @@ -334,7 +329,7 @@
    1.30  
    1.31      if (map->size > 0) {
    1.32          struct cx_hash_map_s *hash_map = (struct cx_hash_map_s *) map;
    1.33 -        struct cx_hash_map_element_s *elm = NULL;
    1.34 +        struct cx_hash_map_element_s *elm = hash_map->buckets[0];
    1.35          for (; elm == NULL; iter.slot++) {
    1.36              elm = hash_map->buckets[iter.slot];
    1.37          }

mercurial