| ... | ... | @@ -848,7 +848,7 @@ pub fn HashMapUnmanaged( |
| 848 | 848 | return ensureUnusedCapacityContext(self, allocator, additional_size, undefined); |
| 849 | 849 | } |
| 850 | 850 | pub fn ensureUnusedCapacityContext(self: *Self, allocator: *Allocator, additional_size: Size, ctx: Context) !void { |
| 851 | | return ensureTotalCapacityContext(self, allocator, self.capacity() + additional_size, ctx); |
| 851 | return ensureTotalCapacityContext(self, allocator, self.count() + additional_size, ctx); |
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | pub fn clearRetainingCapacity(self: *Self) void { |
| ... | ... | @@ -1956,6 +1956,19 @@ test "std.hash_map getOrPutAdapted" { |
| 1956 | 1956 | } |
| 1957 | 1957 | } |
| 1958 | 1958 | |
| 1959 | test "std.hash_map ensureUnusedCapacity" { |
| 1960 | var map = AutoHashMap(u64, u64).init(testing.allocator); |
| 1961 | defer map.deinit(); |
| 1962 | |
| 1963 | try map.ensureUnusedCapacity(32); |
| 1964 | const capacity = map.capacity(); |
| 1965 | try map.ensureUnusedCapacity(32); |
| 1966 | |
| 1967 | // Repeated ensureUnusedCapacity() calls with no insertions between |
| 1968 | // should not change the capacity. |
| 1969 | try testing.expectEqual(capacity, map.capacity()); |
| 1970 | } |
| 1971 | |
| 1959 | 1972 | test "compile everything" { |
| 1960 | 1973 | std.testing.refAllDecls(AutoHashMap(i32, i32)); |
| 1961 | 1974 | std.testing.refAllDecls(StringHashMap([]const u8)); |