From 9d13537fc760d20ba3fe02efe7bf169a7be4d00d Mon Sep 17 00:00:00 2001 From: Kenneth Myhra Date: Sat, 11 Feb 2023 21:07:58 +0100 Subject: [PATCH] AK: Add function 'shallow_clone()' to HashMap This makes a shallow clone of the HashMap, the items temselves are not cloned in any way. --- AK/HashMap.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/AK/HashMap.h b/AK/HashMap.h index d3e1af9b630..8ddcbf0f6ac 100644 --- a/AK/HashMap.h +++ b/AK/HashMap.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2023, Kenneth Myhra * * SPDX-License-Identifier: BSD-2-Clause */ @@ -280,6 +281,14 @@ public: return hash; } + ErrorOr> clone() + { + HashMap hash_map_clone; + for (auto& it : *this) + TRY(hash_map_clone.try_set(it.key, it.value)); + return hash_map_clone; + } + private: HashTableType m_table; };