Переглянути джерело

AK: Implement `HashTable::try_ensure_capacity`, as used in `HashMap`

This was used in `HashMap::try_ensure_capacity`, but was missing from
`HashTable`s implementation. No one had used
`HashMap::try_ensure_capacity` before so it went unnoticed!
James Puleo 3 роки тому
батько
коміт
10b25d2a57
1 змінених файлів з 6 додано та 0 видалено
  1. 6 0
      AK/HashTable.h

+ 6 - 0
AK/HashTable.h

@@ -205,6 +205,12 @@ public:
         rehash(capacity * 2);
     }
 
+    ErrorOr<void> try_ensure_capacity(size_t capacity)
+    {
+        VERIFY(capacity >= size());
+        return try_rehash(capacity * 2);
+    }
+
     [[nodiscard]] bool contains(T const& value) const
     {
         return find(value) != end();