| ... | ... | @@ -169,6 +169,7 @@ pub fn HashMap(comptime K: type, comptime V: type, comptime hash: fn (key: K) u3 |
| 169 | 169 | /// Increases capacity so that the hash map will be at most |
| 170 | 170 | /// 60% full when expected_count items are put into it |
| 171 | 171 | pub fn ensureCapacity(self: *Self, expected_count: usize) !void { |
| 172 | if (expected_count == 0) return; |
| 172 | 173 | const optimized_capacity = optimizedCapacity(expected_count); |
| 173 | 174 | return self.ensureCapacityExact(optimized_capacity); |
| 174 | 175 | } |
| ... | ... | @@ -473,6 +474,9 @@ test "iterator hash map" { |
| 473 | 474 | var reset_map = AutoHashMap(i32, i32).init(std.testing.allocator); |
| 474 | 475 | defer reset_map.deinit(); |
| 475 | 476 | |
| 477 | // test ensureCapacity with a 0 parameter |
| 478 | try reset_map.ensureCapacity(0); |
| 479 | |
| 476 | 480 | try reset_map.putNoClobber(0, 11); |
| 477 | 481 | try reset_map.putNoClobber(1, 22); |
| 478 | 482 | try reset_map.putNoClobber(2, 33); |