From 1dd53ce54c2008e3a11a636a496853cf6f9a5d65 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 24 Jan 2020 09:11:53 +0100 Subject: Convert hash map to gc, implement more instructions and call command --- include/std_gc/hash_map.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 include/std_gc/hash_map.h (limited to 'include/std_gc') 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 + +/* 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 */ -- cgit v1.2.3