aboutsummaryrefslogtreecommitdiff
path: root/src/map.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-07-04 12:37:21 +0100
committergingerBill <bill@gingerbill.org>2021-07-04 12:37:21 +0100
commit4b831dbdddb92c4dbe32dc7b2a6a647febddf5dc (patch)
tree09afd0b98df36a09865da325c7cf7d8efd644b60 /src/map.cpp
parenta01d6dcea729fd39df306a3f9743a78fe9258cd7 (diff)
Try `try` and `or_else` built-in procedures with operators `try` and `try else`
Diffstat (limited to 'src/map.cpp')
-rw-r--r--src/map.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/map.cpp b/src/map.cpp
index 85836fccb..fc23c9aec 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -69,6 +69,7 @@ struct Map {
template <typename T> void map_init (Map<T> *h, gbAllocator a, isize capacity = 16);
template <typename T> void map_destroy (Map<T> *h);
template <typename T> T * map_get (Map<T> *h, HashKey const &key);
+template <typename T> T & map_must_get (Map<T> *h, HashKey const &key);
template <typename T> void map_set (Map<T> *h, HashKey const &key, T const &value);
template <typename T> void map_remove (Map<T> *h, HashKey const &key);
template <typename T> void map_clear (Map<T> *h);
@@ -203,6 +204,13 @@ T *map_get(Map<T> *h, HashKey const &key) {
}
template <typename T>
+T &map_must_get(Map<T> *h, HashKey const &key) {
+ isize index = map__find(h, key).entry_index;
+ GB_ASSERT(index >= 0);
+ return h->entries[index].value;
+}
+
+template <typename T>
void map_set(Map<T> *h, HashKey const &key, T const &value) {
isize index;
MapFindResult fr;