aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/std/hash_map.zig15
1 files changed, 14 insertions, 1 deletions
diff --git a/lib/std/hash_map.zig b/lib/std/hash_map.zig
index d6762c9d3b..ef97e7d7fa 100644
--- a/lib/std/hash_map.zig
+++ b/lib/std/hash_map.zig
@@ -848,7 +848,7 @@ pub fn HashMapUnmanaged(
return ensureUnusedCapacityContext(self, allocator, additional_size, undefined);
}
pub fn ensureUnusedCapacityContext(self: *Self, allocator: *Allocator, additional_size: Size, ctx: Context) !void {
- return ensureTotalCapacityContext(self, allocator, self.capacity() + additional_size, ctx);
+ return ensureTotalCapacityContext(self, allocator, self.count() + additional_size, ctx);
}
pub fn clearRetainingCapacity(self: *Self) void {
@@ -1956,6 +1956,19 @@ test "std.hash_map getOrPutAdapted" {
}
}
+test "std.hash_map ensureUnusedCapacity" {
+ var map = AutoHashMap(u64, u64).init(testing.allocator);
+ defer map.deinit();
+
+ try map.ensureUnusedCapacity(32);
+ const capacity = map.capacity();
+ try map.ensureUnusedCapacity(32);
+
+ // Repeated ensureUnusedCapacity() calls with no insertions between
+ // should not change the capacity.
+ try testing.expectEqual(capacity, map.capacity());
+}
+
test "compile everything" {
std.testing.refAllDecls(AutoHashMap(i32, i32));
std.testing.refAllDecls(StringHashMap([]const u8));