diff options
Diffstat (limited to 'include/std_gc')
-rw-r--r-- | include/std_gc/hash_map.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/include/std_gc/hash_map.h b/include/std_gc/hash_map.h new file mode 100644 index 0000000..e67dd75 --- /dev/null +++ b/include/std_gc/hash_map.h @@ -0,0 +1,29 @@ +#ifndef TSL_HASH_MAP_H +#define TSL_HASH_MAP_H + +#include "../value.h" +#include <stdint.h> + +/* TODO: Optimize small hash map by using the members of the struct instead of allocating on heap */ +typedef struct { + void *buckets_data; /* value=TslHashMapNode */ + size_t buckets_size; + size_t buckets_capacity; +} TslHashMap; + +void tsl_hash_map_init(TslHashMap *self); + +int tsl_hash_map_insert(TslHashMap *self, const TslValue *key, TslValue *value); +/* + Get a reference to the value by key @key, or NULL if it doesn't exist. + The returned pointer is only valid until until reallocation after after insert inserting a new value into the hash map. +*/ +TslValue* tsl_hash_map_get(TslHashMap *self, const TslValue *key); +/* + Get a reference to the value by key @key, or insert a new value for the key (a TslValue). + Returns NULL on failure. + The returned pointer is only valid until until reallocation after after insert inserting a new value into the hash map. +*/ +TslValue* tsl_hash_map_get_or_create(TslHashMap *self, const TslValue *key); + +#endif /* TSL_HASH_MAP_H */ |