diff options
| author | gingerBill <bill@gingerbill.org> | 2021-07-04 12:37:21 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-07-04 12:37:21 +0100 |
| commit | 4b831dbdddb92c4dbe32dc7b2a6a647febddf5dc (patch) | |
| tree | 09afd0b98df36a09865da325c7cf7d8efd644b60 /src/string_map.cpp | |
| parent | a01d6dcea729fd39df306a3f9743a78fe9258cd7 (diff) | |
Try `try` and `or_else` built-in procedures with operators `try` and `try else`
Diffstat (limited to 'src/string_map.cpp')
| -rw-r--r-- | src/string_map.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/string_map.cpp b/src/string_map.cpp index 7a446937a..09e125800 100644 --- a/src/string_map.cpp +++ b/src/string_map.cpp @@ -54,6 +54,10 @@ template <typename T> T * string_map_get (StringMap<T> *h, char co template <typename T> T * string_map_get (StringMap<T> *h, String const &key); template <typename T> T * string_map_get (StringMap<T> *h, StringHashKey const &key); +template <typename T> T & string_map_must_get (StringMap<T> *h, char const *key); +template <typename T> T & string_map_must_get (StringMap<T> *h, String const &key); +template <typename T> T & string_map_must_get (StringMap<T> *h, StringHashKey const &key); + template <typename T> void string_map_set (StringMap<T> *h, StringHashKey const &key, T const &value); template <typename T> void string_map_set (StringMap<T> *h, String const &key, T const &value); template <typename T> void string_map_set (StringMap<T> *h, char const *key, T const &value); @@ -188,6 +192,23 @@ gb_inline T *string_map_get(StringMap<T> *h, char const *key) { } template <typename T> +T &string_map_must_get(StringMap<T> *h, StringHashKey const &key) { + isize index = string_map__find(h, key).entry_index; + GB_ASSERT(index >= 0); + return h->entries[index].value; +} + +template <typename T> +gb_inline T &string_map_must_get(StringMap<T> *h, String const &key) { + return string_map_must_get(h, string_hash_string(key)); +} + +template <typename T> +gb_inline T &string_map_must_get(StringMap<T> *h, char const *key) { + return string_map_must_get(h, string_hash_string(make_string_c(key))); +} + +template <typename T> void string_map_set(StringMap<T> *h, StringHashKey const &key, T const &value) { isize index; StringMapFindResult fr; |