| ... | @@ -158,10 +158,20 @@ pub fn ArrayHashMap( | ... | @@ -158,10 +158,20 @@ pub fn ArrayHashMap( |
| 158 | return self.unmanaged.getOrPutValue(self.allocator, key, value); | 158 | return self.unmanaged.getOrPutValue(self.allocator, key, value); |
| 159 | } | 159 | } |
| 160 | | 160 | |
| | 161 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. |
| | 162 | pub const ensureCapacity = ensureTotalCapacity; |
| | 163 | |
| 161 | /// Increases capacity, guaranteeing that insertions up until the | 164 | /// Increases capacity, guaranteeing that insertions up until the |
| 162 | /// `expected_count` will not cause an allocation, and therefore cannot fail. | 165 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| 163 | pub fn ensureCapacity(self: *Self, new_capacity: usize) !void { | 166 | pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void { |
| 164 | return self.unmanaged.ensureCapacity(self.allocator, new_capacity); | 167 | return self.unmanaged.ensureTotalCapacity(self.allocator, new_capacity); |
| | 168 | } |
| | 169 | |
| | 170 | /// Increases capacity, guaranteeing that insertions up until |
| | 171 | /// `additional_count` **more** items will not cause an allocation, and |
| | 172 | /// therefore cannot fail. |
| | 173 | pub fn ensureUnusedCapacity(self: *Self, additional_count: usize) !void { |
| | 174 | return self.unmanaged.ensureUnusedCapacity(self.allocator, additional_count); |
| 165 | } | 175 | } |
| 166 | | 176 | |
| 167 | /// Returns the number of total elements which may be present before it is | 177 | /// Returns the number of total elements which may be present before it is |
| ... | @@ -472,10 +482,13 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -472,10 +482,13 @@ pub fn ArrayHashMapUnmanaged( |
| 472 | return res.entry; | 482 | return res.entry; |
| 473 | } | 483 | } |
| 474 | | 484 | |
| | 485 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. |
| | 486 | pub const ensureCapacity = ensureTotalCapacity; |
| | 487 | |
| 475 | /// Increases capacity, guaranteeing that insertions up until the | 488 | /// Increases capacity, guaranteeing that insertions up until the |
| 476 | /// `expected_count` will not cause an allocation, and therefore cannot fail. | 489 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| 477 | pub fn ensureCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void { | 490 | pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void { |
| 478 | try self.entries.ensureCapacity(allocator, new_capacity); | 491 | try self.entries.ensureTotalCapacity(allocator, new_capacity); |
| 479 | if (new_capacity <= linear_scan_max) return; | 492 | if (new_capacity <= linear_scan_max) return; |
| 480 | | 493 | |
| 481 | // Ensure that the indexes will be at most 60% full if | 494 | // Ensure that the indexes will be at most 60% full if |
| ... | @@ -501,6 +514,17 @@ pub fn ArrayHashMapUnmanaged( | ... | @@ -501,6 +514,17 @@ pub fn ArrayHashMapUnmanaged( |
| 501 | } | 514 | } |
| 502 | } | 515 | } |
| 503 | | 516 | |
| | 517 | /// Increases capacity, guaranteeing that insertions up until |
| | 518 | /// `additional_count` **more** items will not cause an allocation, and |
| | 519 | /// therefore cannot fail. |
| | 520 | pub fn ensureUnusedCapacity( |
| | 521 | self: *Self, |
| | 522 | allocator: *Allocator, |
| | 523 | additional_capacity: usize, |
| | 524 | ) !void { |
| | 525 | return self.ensureTotalCapacity(allocator, self.count() + additional_capacity); |
| | 526 | } |
| | 527 | |
| 504 | /// Returns the number of total elements which may be present before it is | 528 | /// Returns the number of total elements which may be present before it is |
| 505 | /// no longer guaranteed that no allocations will be performed. | 529 | /// no longer guaranteed that no allocations will be performed. |
| 506 | pub fn capacity(self: Self) usize { | 530 | pub fn capacity(self: Self) usize { |