diff --git a/hash_map.c b/hash_map.c index b0fe7d3..a4aa454 100644 --- a/hash_map.c +++ b/hash_map.c @@ -42,17 +42,23 @@ void hash_map_insert(HashMap *self, void *key, void *value) { } List hash_map_keys(HashMap *self) { - List keys = list_init(self->key_size); - for(size_t bucket_index = 0; bucket_index < CUTES_HASH_MAP_BUCKETS; ++bucket_index) - for(size_t key_index = 0; key_index < self->buckets[bucket_index].len; ++key_index) - list_add(&keys, list_at(self->buckets + bucket_index, key_index)); + List keys = list_from_type(void*); + for(size_t bucket_index = 0; bucket_index < CUTES_HASH_MAP_BUCKETS; ++bucket_index) { + for(size_t key_index = 0; key_index < self->buckets[bucket_index].len; ++key_index) { + void *key = list_at(self->buckets + bucket_index, key_index) + sizeof(uintptr_t); + list_add(&keys, &key); + } + } return keys; } List hash_map_values(HashMap *self) { - List values = list_init(self->value_size); - for(size_t bucket_index = 0; bucket_index < CUTES_HASH_MAP_BUCKETS; ++bucket_index) - for(size_t value_index = 0; value_index < self->buckets[bucket_index].len; ++value_index) - list_add(&values, ((char*)list_at(self->buckets + bucket_index, value_index)) + (sizeof(uintptr_t) + self->key_size)); + List values = list_from_type(void*); + for(size_t bucket_index = 0; bucket_index < CUTES_HASH_MAP_BUCKETS; ++bucket_index) { + for(size_t value_index = 0; value_index < self->buckets[bucket_index].len; ++value_index) { + void *value = ((char*)list_at(self->buckets + bucket_index, value_index)) + (sizeof(uintptr_t) + self->key_size); + list_add(&values, &value); + } + } return values; }