| ... | ... | @@ -616,44 +616,44 @@ pub fn ArrayHashMapUnmanaged( |
| 616 | 616 | |
| 617 | 617 | /// Convert from an unmanaged map to a managed map. After calling this, |
| 618 | 618 | /// the promoted map should no longer be used. |
| 619 | | pub fn promote(self: Self, allocator: Allocator) Managed { |
| 619 | pub fn promote(self: Self, gpa: Allocator) Managed { |
| 620 | 620 | if (@sizeOf(Context) != 0) |
| 621 | 621 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call promoteContext instead."); |
| 622 | | return self.promoteContext(allocator, undefined); |
| 622 | return self.promoteContext(gpa, undefined); |
| 623 | 623 | } |
| 624 | | pub fn promoteContext(self: Self, allocator: Allocator, ctx: Context) Managed { |
| 624 | pub fn promoteContext(self: Self, gpa: Allocator, ctx: Context) Managed { |
| 625 | 625 | return .{ |
| 626 | 626 | .unmanaged = self, |
| 627 | | .allocator = allocator, |
| 627 | .allocator = gpa, |
| 628 | 628 | .ctx = ctx, |
| 629 | 629 | }; |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | | pub fn init(allocator: Allocator, key_list: []const K, value_list: []const V) Oom!Self { |
| 632 | pub fn init(gpa: Allocator, key_list: []const K, value_list: []const V) Oom!Self { |
| 633 | 633 | var self: Self = .{}; |
| 634 | | errdefer self.deinit(allocator); |
| 635 | | try self.reinit(allocator, key_list, value_list); |
| 634 | errdefer self.deinit(gpa); |
| 635 | try self.reinit(gpa, key_list, value_list); |
| 636 | 636 | return self; |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | | pub fn reinit(self: *Self, allocator: Allocator, key_list: []const K, value_list: []const V) Oom!void { |
| 640 | | try self.entries.resize(allocator, key_list.len); |
| 639 | pub fn reinit(self: *Self, gpa: Allocator, key_list: []const K, value_list: []const V) Oom!void { |
| 640 | try self.entries.resize(gpa, key_list.len); |
| 641 | 641 | @memcpy(self.keys(), key_list); |
| 642 | 642 | if (@sizeOf(V) != 0) { |
| 643 | 643 | assert(key_list.len == value_list.len); |
| 644 | 644 | @memcpy(self.values(), value_list); |
| 645 | 645 | } |
| 646 | | try self.reIndex(allocator); |
| 646 | try self.reIndex(gpa); |
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | /// Frees the backing allocation and leaves the map in an undefined state. |
| 650 | 650 | /// Note that this does not free keys or values. You must take care of that |
| 651 | 651 | /// before calling this function, if it is needed. |
| 652 | | pub fn deinit(self: *Self, allocator: Allocator) void { |
| 652 | pub fn deinit(self: *Self, gpa: Allocator) void { |
| 653 | 653 | self.pointer_stability.assertUnlocked(); |
| 654 | | self.entries.deinit(allocator); |
| 654 | self.entries.deinit(gpa); |
| 655 | 655 | if (self.index_header) |header| { |
| 656 | | header.free(allocator); |
| 656 | header.free(gpa); |
| 657 | 657 | } |
| 658 | 658 | self.* = undefined; |
| 659 | 659 | } |
| ... | ... | @@ -691,13 +691,13 @@ pub fn ArrayHashMapUnmanaged( |
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | /// Clears the map and releases the backing allocation |
| 694 | | pub fn clearAndFree(self: *Self, allocator: Allocator) void { |
| 694 | pub fn clearAndFree(self: *Self, gpa: Allocator) void { |
| 695 | 695 | self.pointer_stability.lock(); |
| 696 | 696 | defer self.pointer_stability.unlock(); |
| 697 | 697 | |
| 698 | | self.entries.shrinkAndFree(allocator, 0); |
| 698 | self.entries.shrinkAndFree(gpa, 0); |
| 699 | 699 | if (self.index_header) |header| { |
| 700 | | header.free(allocator); |
| 700 | header.free(gpa); |
| 701 | 701 | self.index_header = null; |
| 702 | 702 | } |
| 703 | 703 | } |
| ... | ... | @@ -760,25 +760,25 @@ pub fn ArrayHashMapUnmanaged( |
| 760 | 760 | /// Otherwise, puts a new item with undefined value, and |
| 761 | 761 | /// the `Entry` pointer points to it. Caller should then initialize |
| 762 | 762 | /// the value (but not the key). |
| 763 | | pub fn getOrPut(self: *Self, allocator: Allocator, key: K) Oom!GetOrPutResult { |
| 763 | pub fn getOrPut(self: *Self, gpa: Allocator, key: K) Oom!GetOrPutResult { |
| 764 | 764 | if (@sizeOf(Context) != 0) |
| 765 | 765 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContext instead."); |
| 766 | | return self.getOrPutContext(allocator, key, undefined); |
| 766 | return self.getOrPutContext(gpa, key, undefined); |
| 767 | 767 | } |
| 768 | | pub fn getOrPutContext(self: *Self, allocator: Allocator, key: K, ctx: Context) Oom!GetOrPutResult { |
| 769 | | const gop = try self.getOrPutContextAdapted(allocator, key, ctx, ctx); |
| 768 | pub fn getOrPutContext(self: *Self, gpa: Allocator, key: K, ctx: Context) Oom!GetOrPutResult { |
| 769 | const gop = try self.getOrPutContextAdapted(gpa, key, ctx, ctx); |
| 770 | 770 | if (!gop.found_existing) { |
| 771 | 771 | gop.key_ptr.* = key; |
| 772 | 772 | } |
| 773 | 773 | return gop; |
| 774 | 774 | } |
| 775 | | pub fn getOrPutAdapted(self: *Self, allocator: Allocator, key: anytype, key_ctx: anytype) Oom!GetOrPutResult { |
| 775 | pub fn getOrPutAdapted(self: *Self, gpa: Allocator, key: anytype, key_ctx: anytype) Oom!GetOrPutResult { |
| 776 | 776 | if (@sizeOf(Context) != 0) |
| 777 | 777 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutContextAdapted instead."); |
| 778 | | return self.getOrPutContextAdapted(allocator, key, key_ctx, undefined); |
| 778 | return self.getOrPutContextAdapted(gpa, key, key_ctx, undefined); |
| 779 | 779 | } |
| 780 | | pub fn getOrPutContextAdapted(self: *Self, allocator: Allocator, key: anytype, key_ctx: anytype, ctx: Context) Oom!GetOrPutResult { |
| 781 | | self.ensureTotalCapacityContext(allocator, self.entries.len + 1, ctx) catch |err| { |
| 780 | pub fn getOrPutContextAdapted(self: *Self, gpa: Allocator, key: anytype, key_ctx: anytype, ctx: Context) Oom!GetOrPutResult { |
| 781 | self.ensureTotalCapacityContext(gpa, self.entries.len + 1, ctx) catch |err| { |
| 782 | 782 | // "If key exists this function cannot fail." |
| 783 | 783 | const index = self.getIndexAdapted(key, key_ctx) orelse return err; |
| 784 | 784 | const slice = self.entries.slice(); |
| ... | ... | @@ -858,13 +858,13 @@ pub fn ArrayHashMapUnmanaged( |
| 858 | 858 | } |
| 859 | 859 | } |
| 860 | 860 | |
| 861 | | pub fn getOrPutValue(self: *Self, allocator: Allocator, key: K, value: V) Oom!GetOrPutResult { |
| 861 | pub fn getOrPutValue(self: *Self, gpa: Allocator, key: K, value: V) Oom!GetOrPutResult { |
| 862 | 862 | if (@sizeOf(Context) != 0) |
| 863 | 863 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call getOrPutValueContext instead."); |
| 864 | | return self.getOrPutValueContext(allocator, key, value, undefined); |
| 864 | return self.getOrPutValueContext(gpa, key, value, undefined); |
| 865 | 865 | } |
| 866 | | pub fn getOrPutValueContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) Oom!GetOrPutResult { |
| 867 | | const res = try self.getOrPutContextAdapted(allocator, key, ctx, ctx); |
| 866 | pub fn getOrPutValueContext(self: *Self, gpa: Allocator, key: K, value: V, ctx: Context) Oom!GetOrPutResult { |
| 867 | const res = try self.getOrPutContextAdapted(gpa, key, ctx, ctx); |
| 868 | 868 | if (!res.found_existing) { |
| 869 | 869 | res.key_ptr.* = key; |
| 870 | 870 | res.value_ptr.* = value; |
| ... | ... | @@ -874,32 +874,32 @@ pub fn ArrayHashMapUnmanaged( |
| 874 | 874 | |
| 875 | 875 | /// Increases capacity, guaranteeing that insertions up until the |
| 876 | 876 | /// `expected_count` will not cause an allocation, and therefore cannot fail. |
| 877 | | pub fn ensureTotalCapacity(self: *Self, allocator: Allocator, new_capacity: usize) Oom!void { |
| 877 | pub fn ensureTotalCapacity(self: *Self, gpa: Allocator, new_capacity: usize) Oom!void { |
| 878 | 878 | if (@sizeOf(ByIndexContext) != 0) |
| 879 | 879 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead."); |
| 880 | | return self.ensureTotalCapacityContext(allocator, new_capacity, undefined); |
| 880 | return self.ensureTotalCapacityContext(gpa, new_capacity, undefined); |
| 881 | 881 | } |
| 882 | | pub fn ensureTotalCapacityContext(self: *Self, allocator: Allocator, new_capacity: usize, ctx: Context) Oom!void { |
| 882 | pub fn ensureTotalCapacityContext(self: *Self, gpa: Allocator, new_capacity: usize, ctx: Context) Oom!void { |
| 883 | 883 | self.pointer_stability.lock(); |
| 884 | 884 | defer self.pointer_stability.unlock(); |
| 885 | 885 | |
| 886 | 886 | if (new_capacity <= linear_scan_max) { |
| 887 | | try self.entries.ensureTotalCapacity(allocator, new_capacity); |
| 887 | try self.entries.ensureTotalCapacity(gpa, new_capacity); |
| 888 | 888 | return; |
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | if (self.index_header) |header| { |
| 892 | 892 | if (new_capacity <= header.capacity()) { |
| 893 | | try self.entries.ensureTotalCapacity(allocator, new_capacity); |
| 893 | try self.entries.ensureTotalCapacity(gpa, new_capacity); |
| 894 | 894 | return; |
| 895 | 895 | } |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | | try self.entries.ensureTotalCapacity(allocator, new_capacity); |
| 898 | try self.entries.ensureTotalCapacity(gpa, new_capacity); |
| 899 | 899 | const new_bit_index = try IndexHeader.findBitIndex(new_capacity); |
| 900 | | const new_header = try IndexHeader.alloc(allocator, new_bit_index); |
| 900 | const new_header = try IndexHeader.alloc(gpa, new_bit_index); |
| 901 | 901 | |
| 902 | | if (self.index_header) |old_header| old_header.free(allocator); |
| 902 | if (self.index_header) |old_header| old_header.free(gpa); |
| 903 | 903 | self.insertAllEntriesIntoNewHeader(if (store_hash) {} else ctx, new_header); |
| 904 | 904 | self.index_header = new_header; |
| 905 | 905 | } |
| ... | ... | @@ -909,20 +909,20 @@ pub fn ArrayHashMapUnmanaged( |
| 909 | 909 | /// therefore cannot fail. |
| 910 | 910 | pub fn ensureUnusedCapacity( |
| 911 | 911 | self: *Self, |
| 912 | | allocator: Allocator, |
| 912 | gpa: Allocator, |
| 913 | 913 | additional_capacity: usize, |
| 914 | 914 | ) Oom!void { |
| 915 | 915 | if (@sizeOf(Context) != 0) |
| 916 | 916 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call ensureTotalCapacityContext instead."); |
| 917 | | return self.ensureUnusedCapacityContext(allocator, additional_capacity, undefined); |
| 917 | return self.ensureUnusedCapacityContext(gpa, additional_capacity, undefined); |
| 918 | 918 | } |
| 919 | 919 | pub fn ensureUnusedCapacityContext( |
| 920 | 920 | self: *Self, |
| 921 | | allocator: Allocator, |
| 921 | gpa: Allocator, |
| 922 | 922 | additional_capacity: usize, |
| 923 | 923 | ctx: Context, |
| 924 | 924 | ) Oom!void { |
| 925 | | return self.ensureTotalCapacityContext(allocator, self.count() + additional_capacity, ctx); |
| 925 | return self.ensureTotalCapacityContext(gpa, self.count() + additional_capacity, ctx); |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | 928 | /// Returns the number of total elements which may be present before it is |
| ... | ... | @@ -936,25 +936,25 @@ pub fn ArrayHashMapUnmanaged( |
| 936 | 936 | |
| 937 | 937 | /// Clobbers any existing data. To detect if a put would clobber |
| 938 | 938 | /// existing data, see `getOrPut`. |
| 939 | | pub fn put(self: *Self, allocator: Allocator, key: K, value: V) Oom!void { |
| 939 | pub fn put(self: *Self, gpa: Allocator, key: K, value: V) Oom!void { |
| 940 | 940 | if (@sizeOf(Context) != 0) |
| 941 | 941 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putContext instead."); |
| 942 | | return self.putContext(allocator, key, value, undefined); |
| 942 | return self.putContext(gpa, key, value, undefined); |
| 943 | 943 | } |
| 944 | | pub fn putContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) Oom!void { |
| 945 | | const result = try self.getOrPutContext(allocator, key, ctx); |
| 944 | pub fn putContext(self: *Self, gpa: Allocator, key: K, value: V, ctx: Context) Oom!void { |
| 945 | const result = try self.getOrPutContext(gpa, key, ctx); |
| 946 | 946 | result.value_ptr.* = value; |
| 947 | 947 | } |
| 948 | 948 | |
| 949 | 949 | /// Inserts a key-value pair into the hash map, asserting that no previous |
| 950 | 950 | /// entry with the same key is already present |
| 951 | | pub fn putNoClobber(self: *Self, allocator: Allocator, key: K, value: V) Oom!void { |
| 951 | pub fn putNoClobber(self: *Self, gpa: Allocator, key: K, value: V) Oom!void { |
| 952 | 952 | if (@sizeOf(Context) != 0) |
| 953 | 953 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call putNoClobberContext instead."); |
| 954 | | return self.putNoClobberContext(allocator, key, value, undefined); |
| 954 | return self.putNoClobberContext(gpa, key, value, undefined); |
| 955 | 955 | } |
| 956 | | pub fn putNoClobberContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) Oom!void { |
| 957 | | const result = try self.getOrPutContext(allocator, key, ctx); |
| 956 | pub fn putNoClobberContext(self: *Self, gpa: Allocator, key: K, value: V, ctx: Context) Oom!void { |
| 957 | const result = try self.getOrPutContext(gpa, key, ctx); |
| 958 | 958 | assert(!result.found_existing); |
| 959 | 959 | result.value_ptr.* = value; |
| 960 | 960 | } |
| ... | ... | @@ -987,13 +987,13 @@ pub fn ArrayHashMapUnmanaged( |
| 987 | 987 | } |
| 988 | 988 | |
| 989 | 989 | /// Inserts a new `Entry` into the hash map, returning the previous one, if any. |
| 990 | | pub fn fetchPut(self: *Self, allocator: Allocator, key: K, value: V) Oom!?KV { |
| 990 | pub fn fetchPut(self: *Self, gpa: Allocator, key: K, value: V) Oom!?KV { |
| 991 | 991 | if (@sizeOf(Context) != 0) |
| 992 | 992 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call fetchPutContext instead."); |
| 993 | | return self.fetchPutContext(allocator, key, value, undefined); |
| 993 | return self.fetchPutContext(gpa, key, value, undefined); |
| 994 | 994 | } |
| 995 | | pub fn fetchPutContext(self: *Self, allocator: Allocator, key: K, value: V, ctx: Context) Oom!?KV { |
| 996 | | const gop = try self.getOrPutContext(allocator, key, ctx); |
| 995 | pub fn fetchPutContext(self: *Self, gpa: Allocator, key: K, value: V, ctx: Context) Oom!?KV { |
| 996 | const gop = try self.getOrPutContext(gpa, key, ctx); |
| 997 | 997 | var result: ?KV = null; |
| 998 | 998 | if (gop.found_existing) { |
| 999 | 999 | result = KV{ |
| ... | ... | @@ -1279,20 +1279,20 @@ pub fn ArrayHashMapUnmanaged( |
| 1279 | 1279 | /// Create a copy of the hash map which can be modified separately. |
| 1280 | 1280 | /// The copy uses the same context as this instance, but is allocated |
| 1281 | 1281 | /// with the provided allocator. |
| 1282 | | pub fn clone(self: Self, allocator: Allocator) Oom!Self { |
| 1282 | pub fn clone(self: Self, gpa: Allocator) Oom!Self { |
| 1283 | 1283 | if (@sizeOf(ByIndexContext) != 0) |
| 1284 | 1284 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call cloneContext instead."); |
| 1285 | | return self.cloneContext(allocator, undefined); |
| 1285 | return self.cloneContext(gpa, undefined); |
| 1286 | 1286 | } |
| 1287 | | pub fn cloneContext(self: Self, allocator: Allocator, ctx: Context) Oom!Self { |
| 1287 | pub fn cloneContext(self: Self, gpa: Allocator, ctx: Context) Oom!Self { |
| 1288 | 1288 | var other: Self = .{}; |
| 1289 | | other.entries = try self.entries.clone(allocator); |
| 1290 | | errdefer other.entries.deinit(allocator); |
| 1289 | other.entries = try self.entries.clone(gpa); |
| 1290 | errdefer other.entries.deinit(gpa); |
| 1291 | 1291 | |
| 1292 | 1292 | if (self.index_header) |header| { |
| 1293 | 1293 | // TODO: I'm pretty sure this could be memcpy'd instead of |
| 1294 | 1294 | // doing all this work. |
| 1295 | | const new_header = try IndexHeader.alloc(allocator, header.bit_index); |
| 1295 | const new_header = try IndexHeader.alloc(gpa, header.bit_index); |
| 1296 | 1296 | other.insertAllEntriesIntoNewHeader(if (store_hash) {} else ctx, new_header); |
| 1297 | 1297 | other.index_header = new_header; |
| 1298 | 1298 | } |
| ... | ... | @@ -1318,13 +1318,13 @@ pub fn ArrayHashMapUnmanaged( |
| 1318 | 1318 | /// directly without going through the methods of this map. |
| 1319 | 1319 | /// |
| 1320 | 1320 | /// The time complexity of this operation is O(n). |
| 1321 | | pub fn reIndex(self: *Self, allocator: Allocator) Oom!void { |
| 1321 | pub fn reIndex(self: *Self, gpa: Allocator) Oom!void { |
| 1322 | 1322 | if (@sizeOf(ByIndexContext) != 0) |
| 1323 | 1323 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call reIndexContext instead."); |
| 1324 | | return self.reIndexContext(allocator, undefined); |
| 1324 | return self.reIndexContext(gpa, undefined); |
| 1325 | 1325 | } |
| 1326 | 1326 | |
| 1327 | | pub fn reIndexContext(self: *Self, allocator: Allocator, ctx: Context) Oom!void { |
| 1327 | pub fn reIndexContext(self: *Self, gpa: Allocator, ctx: Context) Oom!void { |
| 1328 | 1328 | // Recompute all hashes. |
| 1329 | 1329 | if (store_hash) { |
| 1330 | 1330 | for (self.keys(), self.entries.items(.hash)) |key, *hash| { |
| ... | ... | @@ -1337,8 +1337,8 @@ pub fn ArrayHashMapUnmanaged( |
| 1337 | 1337 | // We're going to rebuild the index header and replace the existing one (if any). The |
| 1338 | 1338 | // indexes should sized such that they will be at most 60% full. |
| 1339 | 1339 | const bit_index = try IndexHeader.findBitIndex(self.entries.capacity); |
| 1340 | | const new_header = try IndexHeader.alloc(allocator, bit_index); |
| 1341 | | if (self.index_header) |header| header.free(allocator); |
| 1340 | const new_header = try IndexHeader.alloc(gpa, bit_index); |
| 1341 | if (self.index_header) |header| header.free(gpa); |
| 1342 | 1342 | self.insertAllEntriesIntoNewHeader(if (store_hash) {} else ctx, new_header); |
| 1343 | 1343 | self.index_header = new_header; |
| 1344 | 1344 | } |
| ... | ... | @@ -1430,10 +1430,10 @@ pub fn ArrayHashMapUnmanaged( |
| 1430 | 1430 | /// performing hash and equality checks. It is a bug to call this |
| 1431 | 1431 | /// function if the discarded entries require deinitialization. For |
| 1432 | 1432 | /// that use case, `shrinkRetainingCapacity` can be used instead. |
| 1433 | | pub fn shrinkAndFree(self: *Self, allocator: Allocator, new_len: usize) void { |
| 1433 | pub fn shrinkAndFree(self: *Self, gpa: Allocator, new_len: usize) void { |
| 1434 | 1434 | if (@sizeOf(ByIndexContext) != 0) |
| 1435 | 1435 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call shrinkAndFreeContext instead."); |
| 1436 | | return self.shrinkAndFreeContext(allocator, new_len, undefined); |
| 1436 | return self.shrinkAndFreeContext(gpa, new_len, undefined); |
| 1437 | 1437 | } |
| 1438 | 1438 | |
| 1439 | 1439 | /// Shrinks the underlying `Entry` array to `new_len` elements and |
| ... | ... | @@ -1444,7 +1444,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1444 | 1444 | /// function if the discarded entries require deinitialization. For |
| 1445 | 1445 | /// that use case, `shrinkRetainingCapacityContext` can be used |
| 1446 | 1446 | /// instead. |
| 1447 | | pub fn shrinkAndFreeContext(self: *Self, allocator: Allocator, new_len: usize, ctx: Context) void { |
| 1447 | pub fn shrinkAndFreeContext(self: *Self, gpa: Allocator, new_len: usize, ctx: Context) void { |
| 1448 | 1448 | self.pointer_stability.lock(); |
| 1449 | 1449 | defer self.pointer_stability.unlock(); |
| 1450 | 1450 | |
| ... | ... | @@ -1456,7 +1456,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1456 | 1456 | while (i < self.entries.len) : (i += 1) |
| 1457 | 1457 | self.removeFromIndexByIndex(i, if (store_hash) {} else ctx, header); |
| 1458 | 1458 | } |
| 1459 | | self.entries.shrinkAndFree(allocator, new_len); |
| 1459 | self.entries.shrinkAndFree(gpa, new_len); |
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | 1462 | /// Removes the last inserted `Entry` in the hash map and returns it. |
| ... | ... | @@ -2111,11 +2111,11 @@ const IndexHeader = struct { |
| 2111 | 2111 | |
| 2112 | 2112 | /// Allocates an index header, and fills the entryIndexes array with empty. |
| 2113 | 2113 | /// The distance array contents are undefined. |
| 2114 | | fn alloc(allocator: Allocator, new_bit_index: u8) Allocator.Error!*IndexHeader { |
| 2114 | fn alloc(gpa: Allocator, new_bit_index: u8) Allocator.Error!*IndexHeader { |
| 2115 | 2115 | const len = @as(usize, 1) << @as(math.Log2Int(usize), @intCast(new_bit_index)); |
| 2116 | 2116 | const index_size = hash_map.capacityIndexSize(new_bit_index); |
| 2117 | 2117 | const nbytes = @sizeOf(IndexHeader) + index_size * len; |
| 2118 | | const bytes = try allocator.alignedAlloc(u8, @alignOf(IndexHeader), nbytes); |
| 2118 | const bytes = try gpa.alignedAlloc(u8, @alignOf(IndexHeader), nbytes); |
| 2119 | 2119 | @memset(bytes[@sizeOf(IndexHeader)..], 0xff); |
| 2120 | 2120 | const result: *IndexHeader = @alignCast(@ptrCast(bytes.ptr)); |
| 2121 | 2121 | result.* = .{ |
| ... | ... | @@ -2125,11 +2125,11 @@ const IndexHeader = struct { |
| 2125 | 2125 | } |
| 2126 | 2126 | |
| 2127 | 2127 | /// Releases the memory for a header and its associated arrays. |
| 2128 | | fn free(header: *IndexHeader, allocator: Allocator) void { |
| 2128 | fn free(header: *IndexHeader, gpa: Allocator) void { |
| 2129 | 2129 | const index_size = hash_map.capacityIndexSize(header.bit_index); |
| 2130 | 2130 | const ptr: [*]align(@alignOf(IndexHeader)) u8 = @ptrCast(header); |
| 2131 | 2131 | const slice = ptr[0 .. @sizeOf(IndexHeader) + header.length() * index_size]; |
| 2132 | | allocator.free(slice); |
| 2132 | gpa.free(slice); |
| 2133 | 2133 | } |
| 2134 | 2134 | |
| 2135 | 2135 | /// Puts an IndexHeader into the state that it would be in after being freshly allocated. |