diff options
author | dec05eba <dec05eba@protonmail.com> | 2020-01-22 01:47:59 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2020-01-22 01:47:59 +0100 |
commit | 88244bd3070399ba62d79bae6dfdf8b09ff8406d (patch) | |
tree | 6e9f7c5a27fe9c2dc2231b9bc32ea01c3a11d2ac /include/std | |
parent | dea77dd862e71cffb2ebab5079df20e0ebaeddf5 (diff) |
Add get_or_create method for hash map, more efficient than checking and then creating
Diffstat (limited to 'include/std')
-rw-r--r-- | include/std/hash_map.h | 4 |
1 files changed, 3 insertions, 1 deletions
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 */ |