aboutsummaryrefslogtreecommitdiff
path: root/src/std
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2019-03-08 00:09:30 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-25 14:36:46 +0200
commit6bef90418f677f5b971a7a597126d743f8198046 (patch)
treeb8683193dfb7d6a173d6d8ca50d94815910e1b3b /src/std
parent0b282c914bb7e7e761428c9ac7cf5e089773ba8f (diff)
Fix hash_map_get not returning value
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;