From 88244bd3070399ba62d79bae6dfdf8b09ff8406d Mon Sep 17 00:00:00 2001 From: dec05eba Date: Wed, 22 Jan 2020 01:47:59 +0100 Subject: Add get_or_create method for hash map, more efficient than checking and then creating --- include/std/hash_map.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/std/hash_map.h b/include/std/hash_map.h index 986576d..b430d22 100644 --- a/include/std/hash_map.h +++ b/include/std/hash_map.h @@ -17,7 +17,9 @@ void tsl_hash_map_init(TslHashMap *self); void tsl_hash_map_deinit(TslHashMap *self); int tsl_hash_map_insert(TslHashMap *self, const TslStringView *key, const void *data, size_t size, TslHashFunc hash_func); -/* Get a reference to the value by key @key */ +/* Get a reference to the value by key @key, or NULL if it doesn't exist */ void* tsl_hash_map_get(TslHashMap *self, const TslStringView *key, TslHashFunc hash_func); +/* Get a reference to the value by key @key, or insert a new value for the key with a size of @size */ +int tsl_hash_map_get_or_create(TslHashMap *self, const TslStringView *key, size_t size, TslHashFunc hash_func, void **output); #endif /* TSL_HASH_MAP_H */ -- cgit v1.2.3