101 memcmp(elm->key.data.obj, key.data.obj, key.len) == 0) { |
101 memcmp(elm->key.data.obj, key.data.obj, key.len) == 0) { |
102 // overwrite existing element |
102 // overwrite existing element |
103 if (map->store_pointers) { |
103 if (map->store_pointers) { |
104 memcpy(elm->data, &value, sizeof(void *)); |
104 memcpy(elm->data, &value, sizeof(void *)); |
105 } else { |
105 } else { |
106 memcpy(elm->data, value, map->itemsize); |
106 memcpy(elm->data, value, map->item_size); |
107 } |
107 } |
108 } else { |
108 } else { |
109 // allocate new element |
109 // allocate new element |
110 struct cx_hash_map_element_s *e = cxMalloc( |
110 struct cx_hash_map_element_s *e = cxMalloc( |
111 allocator, |
111 allocator, |
112 sizeof(struct cx_hash_map_element_s) + map->itemsize |
112 sizeof(struct cx_hash_map_element_s) + map->item_size |
113 ); |
113 ); |
114 if (e == NULL) { |
114 if (e == NULL) { |
115 return -1; |
115 return -1; |
116 } |
116 } |
117 |
117 |
118 // write the value |
118 // write the value |
119 if (map->store_pointers) { |
119 if (map->store_pointers) { |
120 memcpy(e->data, &value, sizeof(void *)); |
120 memcpy(e->data, &value, sizeof(void *)); |
121 } else { |
121 } else { |
122 memcpy(e->data, value, map->itemsize); |
122 memcpy(e->data, value, map->item_size); |
123 } |
123 } |
124 |
124 |
125 // copy the key |
125 // copy the key |
126 void *kd = cxMalloc(allocator, key.len); |
126 void *kd = cxMalloc(allocator, key.len); |
127 if (kd == NULL) { |
127 if (kd == NULL) { |
432 map->base.allocator = allocator; |
432 map->base.allocator = allocator; |
433 map->base.size = 0; |
433 map->base.size = 0; |
434 |
434 |
435 if (itemsize > 0) { |
435 if (itemsize > 0) { |
436 map->base.store_pointers = false; |
436 map->base.store_pointers = false; |
437 map->base.itemsize = itemsize; |
437 map->base.item_size = itemsize; |
438 } else { |
438 } else { |
439 map->base.store_pointers = true; |
439 map->base.store_pointers = true; |
440 map->base.itemsize = sizeof(void *); |
440 map->base.item_size = sizeof(void *); |
441 } |
441 } |
442 |
442 |
443 return (CxMap *) map; |
443 return (CxMap *) map; |
444 } |
444 } |
445 |
445 |