src/hash_map.c

changeset 574
d566bd3e6af8
parent 573
3f3a0d19db58
child 575
b05935945637
equal deleted inserted replaced
573:3f3a0d19db58 574:d566bd3e6af8
84 while (elm != NULL && elm->key.hash < hash) { 84 while (elm != NULL && elm->key.hash < hash) {
85 prev = elm; 85 prev = elm;
86 elm = elm->next; 86 elm = elm->next;
87 } 87 }
88 88
89 if (elm == NULL || elm->key.hash != hash) { 89 if (elm != NULL && elm->key.hash == hash) {
90 // overwrite existing element
91 elm->data = value;
92 } else {
93 // insert new element
94
90 struct cx_hash_map_element_s *e = cxMalloc(allocator, sizeof(struct cx_hash_map_element_s)); 95 struct cx_hash_map_element_s *e = cxMalloc(allocator, sizeof(struct cx_hash_map_element_s));
91 if (e == NULL) { 96 if (e == NULL) {
92 return -1; 97 return -1;
93 } 98 }
94 99
114 } 119 }
115 e->next = elm; 120 e->next = elm;
116 121
117 // increase the size 122 // increase the size
118 map->size++; 123 map->size++;
119 } else {
120 // (elem != NULL && elem->key.hash == hash) - overwrite value of existing element
121 elm->data = value;
122 } 124 }
123 125
124 return 0; 126 return 0;
125 } 127 }
126 128

mercurial