aboutsummaryrefslogtreecommitdiff
path: root/lib/std/array_hash_map.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-11-05 03:39:01 -0500
committerGitHub <noreply@github.com>2023-11-05 03:39:01 -0500
commitdc63426b1eaef9c65152c8e052e5552e593e9382 (patch)
tree4baa141bdd1da68a3f15164988317350f95b76c7 /lib/std/array_hash_map.zig
parentf24ceec35a6fd1e5e6a671461b78919b5f588a32 (diff)
parenta9002156a09130038abcf418609fea725ce71bc2 (diff)
downloadzig-dc63426b1eaef9c65152c8e052e5552e593e9382.tar.gz
zig-dc63426b1eaef9c65152c8e052e5552e593e9382.zip
Merge pull request #17866 from ziglang/reduce-inline-import
zig reduce: support inlining `@import` and more
Diffstat (limited to 'lib/std/array_hash_map.zig')
-rw-r--r--lib/std/array_hash_map.zig13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/std/array_hash_map.zig b/lib/std/array_hash_map.zig
index 75a86f63f6..bf5f6581ac 100644
--- a/lib/std/array_hash_map.zig
+++ b/lib/std/array_hash_map.zig
@@ -574,6 +574,19 @@ pub fn ArrayHashMapUnmanaged(
};
}
+ pub fn init(allocator: Allocator, key_list: []const K, value_list: []const V) !Self {
+ var self: Self = .{};
+ try self.entries.resize(allocator, key_list.len);
+ errdefer self.entries.deinit(allocator);
+ @memcpy(self.keys(), key_list);
+ if (@sizeOf(V) != 0) {
+ assert(key_list.len == value_list.len);
+ @memcpy(self.values(), value_list);
+ }
+ try self.reIndex(allocator);
+ return self;
+ }
+
/// Frees the backing allocation and leaves the map in an undefined state.
/// Note that this does not free keys or values. You must take care of that
/// before calling this function, if it is needed.