From: Brendan Hansen Date: Fri, 9 Feb 2024 02:50:26 +0000 (-0600) Subject: added: `map.copy` X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=31e4959fcbf3feca477ee23881527666586f919a;p=onyx.git added: `map.copy` --- diff --git a/core/container/map.onyx b/core/container/map.onyx index 7aff718c..0efaa9cd 100644 --- a/core/container/map.onyx +++ b/core/container/map.onyx @@ -101,6 +101,18 @@ free :: (use map: &Map) { if entries.data != null do array.free(&entries); } +#doc """ + Shallow copies a map using the allocator provided if one is provided, or the allocator on the old map otherwise. +""" +copy :: (oldMap: &Map, allocator: ? Allocator = .None) -> Map(oldMap.Key_Type, oldMap.Value_Type) { + newMap: typeof *oldMap; + newMap.allocator = allocator ?? oldMap.allocator; + newMap.hashes = array.copy(oldMap.hashes, newMap.allocator); + newMap.entries = array.copy(&oldMap.entries, newMap.allocator); + + return newMap; +} + #doc """ Sets the value at the specified key, or creates a new entry if the key was not already present.