Explorar o código

AK: Add function 'shallow_clone()' to HashMap

This makes a shallow clone of the HashMap, the items temselves are not
cloned in any way.
Kenneth Myhra %!s(int64=2) %!d(string=hai) anos
pai
achega
9d13537fc7
Modificáronse 1 ficheiros con 9 adicións e 0 borrados
  1. 9 0
      AK/HashMap.h

+ 9 - 0
AK/HashMap.h

@@ -1,5 +1,6 @@
 /*
 /*
  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2023, Kenneth Myhra <kennethmyhra@serenityos.org>
  *
  *
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
@@ -280,6 +281,14 @@ public:
         return hash;
         return hash;
     }
     }
 
 
+    ErrorOr<HashMap<K, V>> clone()
+    {
+        HashMap<K, V> hash_map_clone;
+        for (auto& it : *this)
+            TRY(hash_map_clone.try_set(it.key, it.value));
+        return hash_map_clone;
+    }
+
 private:
 private:
     HashTableType m_table;
     HashTableType m_table;
 };
 };