From c68fe7634341e97c3246b627a20fa9487586ffcb Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 21 Aug 2019 06:08:00 +0200 Subject: hash map contains --- src/std/hash_map.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/std') diff --git a/src/std/hash_map.c b/src/std/hash_map.c index 2b29f2e..48e9e38 100644 --- a/src/std/hash_map.c +++ b/src/std/hash_map.c @@ -192,7 +192,8 @@ bool hash_map_get(HashMap *self, BufferView key, void *value) { BufferView bucket_key; bucket_key = bucket_node_get_key(bucket_node); if(hash == bucket_node_get_hash(bucket_node) && self->compare_func(&key, &bucket_key) == 0) { - am_memcpy(value, bucket_node_get_value(bucket_node), self->value_type_size); + if(value) + am_memcpy(value, bucket_node_get_value(bucket_node), self->value_type_size); return bool_true; } } @@ -200,6 +201,10 @@ bool hash_map_get(HashMap *self, BufferView key, void *value) { return bool_false; } +bool hash_map_contains(HashMap *self, BufferView key) { + return hash_map_get(self, key, NULL); +} + #define MIN(a, b) ((a) < (b) ? (a) : (b)) int hash_map_compare_string(const void *a, const void *b) { -- cgit v1.2.3