chore: documentation and readability of hash_map.c

main
Sara 2024-09-25 10:39:27 +02:00
parent 2021092a17
commit e99e391ffa
1 changed files with 2 additions and 2 deletions

View File

@ -33,9 +33,9 @@ void *hash_map_get_raw(HashMap *self, void *key) {
void hash_map_insert(HashMap *self, void *key, void *value) { void hash_map_insert(HashMap *self, void *key, void *value) {
uintptr_t hash = self->hasher(key); uintptr_t hash = self->hasher(key);
// stage key-value-pair data // stage key-value-pair data
char data[sizeof(uintptr_t) + self->key_size + self->value_size]; char data[self->buckets[0].element_size];
memcpy(data, &hash, sizeof(uintptr_t)); // copy key hash into start of data memcpy(data, &hash, sizeof(uintptr_t)); // copy key hash into start of data
memcpy(data + sizeof(uintptr_t), key, self->key_size); memcpy(data + sizeof(uintptr_t), key, self->key_size); // copy key after hash
memcpy(data + sizeof(uintptr_t) + self->key_size, value, self->value_size); // copy value into end of data memcpy(data + sizeof(uintptr_t) + self->key_size, value, self->value_size); // copy value into end of data
// insert staged data into list // insert staged data into list
list_add(self->buckets + (hash % CUTES_HASH_MAP_BUCKETS), data); list_add(self->buckets + (hash % CUTES_HASH_MAP_BUCKETS), data);