aboutsummaryrefslogtreecommitdiff
path: root/src/std
diff options
context:
space:
mode:
Diffstat (limited to 'src/std')
-rw-r--r--src/std/hash_map.c19
1 files changed, 7 insertions, 12 deletions
diff --git a/src/std/hash_map.c b/src/std/hash_map.c
index 7c3d943..9f58f6f 100644
--- a/src/std/hash_map.c
+++ b/src/std/hash_map.c
@@ -105,13 +105,6 @@ static void hash_map_reorder_nodes(HashMap *self, usize end_index) {
BufferView bucket_key;
usize bucket_index;
- /* Node between current and previous has been removed, chain previous and current */
- if(prev_bucket_node && !bucket_node_get_next(prev_bucket_node))
- bucket_node_set_next(prev_bucket_node, bucket_node);
-
- if(!prev_bucket_node)
- bucket->start = bucket_node;
-
bucket_key = bucket_node_get_key(bucket_node);
bucket_index = self->hash_func((const u8*)bucket_key.data, bucket_key.size) % bucket_size;
if(bucket_index != index) {
@@ -125,7 +118,9 @@ static void hash_map_reorder_nodes(HashMap *self, usize end_index) {
new_bucket->start = moved_node;
/* Mark bucket node to be removed bucket by dechaining */
if(prev_bucket_node)
- bucket_node_set_next(prev_bucket_node, NULL);
+ bucket_node_set_next(prev_bucket_node, bucket_node);
+ else
+ bucket->start = bucket_node;
} else {
prev_bucket_node = bucket_node;
bucket_node = bucket_node_get_next(bucket_node);
@@ -177,13 +172,13 @@ bool hash_map_get(HashMap *self, BufferView key, void *value) {
bucket_index = self->hash_func((const u8*)key.data, key.size) % bucket_size;
bucket = ((HashMapBucket*)self->buckets.data) + bucket_index;
- for(bucket_node = bucket->start; bucket_node; bucket_node_get_next(bucket_node)) {
+ for(bucket_node = bucket->start; bucket_node; bucket_node = bucket_node_get_next(bucket_node)) {
BufferView bucket_key;
bucket_key = bucket_node_get_key(bucket_node);
- bucket_index = self->hash_func((const u8*)bucket_key.data, bucket_key.size) % bucket_size;
- bucket_index %= bucket_size;
- if(self->compare_func(value, bucket_node_get_value(bucket_node)) == 0)
+ if(self->compare_func(&key, &bucket_key) == 0) {
+ am_memcpy(value, bucket_node_get_value(bucket_node), self->type_size);
return bool_true;
+ }
}
return bool_false;