diff --git a/AK/HashMap.h b/AK/HashMap.h index e5e9bb66fd..3eb103abdd 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -139,6 +139,16 @@ public: return find(key)->value; } + template + V& ensure(K const& key, Callback initialization_callback) + { + auto it = find(key); + if (it == end()) { + set(key, initialization_callback()); + } + return find(key)->value; + } + [[nodiscard]] Vector keys() const { Vector list;