src/hash_map.c

changeset 574
d566bd3e6af8
parent 573
3f3a0d19db58
child 575
b05935945637
     1.1 --- a/src/hash_map.c	Fri Aug 12 16:47:11 2022 +0200
     1.2 +++ b/src/hash_map.c	Fri Aug 12 16:48:59 2022 +0200
     1.3 @@ -86,7 +86,12 @@
     1.4          elm = elm->next;
     1.5      }
     1.6  
     1.7 -    if (elm == NULL || elm->key.hash != hash) {
     1.8 +    if (elm != NULL && elm->key.hash == hash) {
     1.9 +        // overwrite existing element
    1.10 +        elm->data = value;
    1.11 +    } else {
    1.12 +        // insert new element
    1.13 +
    1.14          struct cx_hash_map_element_s *e = cxMalloc(allocator, sizeof(struct cx_hash_map_element_s));
    1.15          if (e == NULL) {
    1.16              return -1;
    1.17 @@ -116,9 +121,6 @@
    1.18  
    1.19          // increase the size
    1.20          map->size++;
    1.21 -    } else {
    1.22 -        // (elem != NULL && elem->key.hash == hash) - overwrite value of existing element
    1.23 -        elm->data = value;
    1.24      }
    1.25  
    1.26      return 0;

mercurial