| ... | ... | @@ -483,10 +483,20 @@ pub fn HashMap( |
| 483 | 483 | return self.unmanaged.getOrPutValueContext(self.allocator, key, value, self.ctx); |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. |
| 487 | pub const ensureCapacity = ensureTotalCapacity; |
| 488 | |
| 486 | 489 | /// Increases capacity, guaranteeing that insertions up until the |
| 487 | 490 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| 488 | | pub fn ensureCapacity(self: *Self, expected_count: Size) !void { |
| 489 | | return self.unmanaged.ensureCapacityContext(self.allocator, expected_count, self.ctx); |
| 491 | pub fn ensureTotalCapacity(self: *Self, expected_count: Size) !void { |
| 492 | return self.unmanaged.ensureTotalCapacityContext(self.allocator, expected_count, self.ctx); |
| 493 | } |
| 494 | |
| 495 | /// Increases capacity, guaranteeing that insertions up until |
| 496 | /// `additional_count` **more** items will not cause an allocation, and |
| 497 | /// therefore cannot fail. |
| 498 | pub fn ensureUnusedCapacity(self: *Self, additional_count: Size) !void { |
| 499 | return self.unmanaged.ensureUnusedCapacityContext(self.allocator, additional_count, self.ctx); |
| 490 | 500 | } |
| 491 | 501 | |
| 492 | 502 | /// Returns the number of total elements which may be present before it is |
| ... | ... | @@ -821,16 +831,26 @@ pub fn HashMapUnmanaged( |
| 821 | 831 | return new_cap; |
| 822 | 832 | } |
| 823 | 833 | |
| 824 | | pub fn ensureCapacity(self: *Self, allocator: *Allocator, new_size: Size) !void { |
| 834 | /// Deprecated: call `ensureUnusedCapacity` or `ensureTotalCapacity`. |
| 835 | pub const ensureCapacity = ensureTotalCapacity; |
| 836 | |
| 837 | pub fn ensureTotalCapacity(self: *Self, allocator: *Allocator, new_size: Size) !void { |
| 825 | 838 | if (@sizeOf(Context) != 0) |
| 826 | | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureCapacityContext instead."); |
| 827 | | return ensureCapacityContext(self, allocator, new_size, undefined); |
| 839 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead."); |
| 840 | return ensureTotalCapacityContext(self, allocator, new_size, undefined); |
| 828 | 841 | } |
| 829 | | pub fn ensureCapacityContext(self: *Self, allocator: *Allocator, new_size: Size, ctx: Context) !void { |
| 842 | pub fn ensureTotalCapacityContext(self: *Self, allocator: *Allocator, new_size: Size, ctx: Context) !void { |
| 830 | 843 | if (new_size > self.size) |
| 831 | 844 | try self.growIfNeeded(allocator, new_size - self.size, ctx); |
| 832 | 845 | } |
| 833 | 846 | |
| 847 | pub fn ensureUnusedCapacity(self: *Self, allocator: *Allocator, additional_size: Size) !void { |
| 848 | return ensureUnusedCapacityContext(self, allocator, additional_size, undefined); |
| 849 | } |
| 850 | pub fn ensureUnusedCapacityContext(self: *Self, allocator: *Allocator, additional_size: Size, ctx: Context) !void { |
| 851 | return ensureTotalCapacityContext(self, allocator, self.capacity() + additional_size, ctx); |
| 852 | } |
| 853 | |
| 834 | 854 | pub fn clearRetainingCapacity(self: *Self) void { |
| 835 | 855 | if (self.metadata) |_| { |
| 836 | 856 | self.initMetadatas(); |