From c68fe7634341e97c3246b627a20fa9487586ffcb Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 21 Aug 2019 06:08:00 +0200 Subject: hash map contains --- include/program.h | 5 +++++ include/std/hash_map.h | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/program.h b/include/program.h index 543b38d..075bfca 100644 --- a/include/program.h +++ b/include/program.h @@ -30,6 +30,7 @@ #define AMAL_PROGRAM_INVALID_EXTERNAL_FUNCTIONS_SIZE -18 #define AMAL_PROGRAM_INSTRUCTION_INVALID_EXTERN_FUNC_INDEX -19 #define AMAL_PROGRAM_NO_SUCH_EXTERNAL_FUNCTION -20 +#define AMAL_PROGRAM_EXTERN_FUNC_ALREADY_EXISTS -21 #define AMAL_PROGRAM_MAGIC_NUMBER (u32)0xdec05eba #define AMAL_PROGRAM_MAJOR_VERSION 1 @@ -66,6 +67,10 @@ typedef struct { CHECK_RESULT int amal_program_init(amal_program *self); void amal_program_deinit(amal_program *self); +/* + returns @AMAL_PROGRAM_EXTERN_FUNC_ALREADY_EXISTS if a function with the name @name already exists + in the program +*/ CHECK_RESULT int amal_program_add_extern_func(amal_program *self, BufferView name, void *func_ptr, int args_byte_size); CHECK_RESULT int amal_program_append_bytecode(amal_program *self, Bytecode *bytecode); diff --git a/include/std/hash_map.h b/include/std/hash_map.h index d789db4..c9e5b51 100644 --- a/include/std/hash_map.h +++ b/include/std/hash_map.h @@ -25,15 +25,17 @@ struct HashMap { CHECK_RESULT int hash_map_init(HashMap *self, ArenaAllocator *allocator, usize value_type_size, HashMapCompare key_compare_func, HashMapHash key_hash_func); /* -Not thread-safe. -Expected @value size to be @self->value_type_size. + Not thread-safe. + Expected @value size to be @self->value_type_size. */ CHECK_RESULT int hash_map_insert(HashMap *self, BufferView key, void *value); /* -Thread-safe unless @hash_map_insert is used in another thread at the same time. -Expected @value size to be @self->value_type_size. + Thread-safe unless @hash_map_insert is used in another thread at the same time. + Expected @value size to be @self->value_type_size. + If @value is NULL, then the value is not copied and the functions works the same as @hash_map_contains */ CHECK_RESULT bool hash_map_get(HashMap *self, BufferView key, void *value); +CHECK_RESULT bool hash_map_contains(HashMap *self, BufferView key); int hash_map_compare_string(const void *a, const void *b); -- cgit v1.2.3