src/hash_map.c

changeset 575
b05935945637
parent 574
d566bd3e6af8
child 630
ac5e7f789048
equal deleted inserted replaced
574:d566bd3e6af8 575:b05935945637
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 && elm->key.len == key.len &&
90 memcmp(elm->key.data.obj, key.data.obj, key.len) == 0) {
90 // overwrite existing element 91 // overwrite existing element
91 elm->data = value; 92 elm->data = value;
92 } else { 93 } else {
93 // insert new element 94 // allocate new element
94
95 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));
96 if (e == NULL) { 96 if (e == NULL) {
97 return -1; 97 return -1;
98 } 98 }
99 99

mercurial