| ... | ... | @@ -158,10 +158,20 @@ pub fn ArrayHashMap( |
| 158 | 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 | 164 | /// Increases capacity, guaranteeing that insertions up until the |
| 162 | 165 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| 163 | | pub fn ensureCapacity(self: *Self, new_capacity: usize) !void { |
| 164 | | return self.unmanaged.ensureCapacity(self.allocator, new_capacity); |
| 166 | pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void { |
| 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 | 177 | /// Returns the number of total elements which may be present before it is |
| ... | ... | @@ -472,10 +482,13 @@ pub fn ArrayHashMapUnmanaged( |
| 472 | 482 | return res.entry; |
| 473 | 483 | } |
| 474 | 484 | |
| 485 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. |
| 486 | pub const ensureCapacity = ensureTotalCapacity; |
| 487 | |
| 475 | 488 | /// Increases capacity, guaranteeing that insertions up until the |
| 476 | 489 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| 477 | | pub fn ensureCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void { |
| 478 | | try self.entries.ensureCapacity(allocator, new_capacity); |
| 490 | pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_capacity: usize) !void { |
| 491 | try self.entries.ensureTotalCapacity(allocator, new_capacity); |
| 479 | 492 | if (new_capacity <= linear_scan_max) return; |
| 480 | 493 | |
| 481 | 494 | // Ensure that the indexes will be at most 60% full if |
| ... | ... | @@ -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 | 528 | /// Returns the number of total elements which may be present before it is |
| 505 | 529 | /// no longer guaranteed that no allocations will be performed. |
| 506 | 530 | pub fn capacity(self: Self) usize { |