| ... | @@ -471,13 +471,13 @@ pub fn HashMap( | ... | @@ -471,13 +471,13 @@ pub fn HashMap( |
| 471 | | 471 | |
| 472 | /// Create an iterator over the keys in the map. | 472 | /// Create an iterator over the keys in the map. |
| 473 | /// The iterator is invalidated if the map is modified. | 473 | /// The iterator is invalidated if the map is modified. |
| 474 | pub fn keyIterator(self: *const Self) KeyIterator { | 474 | pub fn keyIterator(self: Self) KeyIterator { |
| 475 | return self.unmanaged.keyIterator(); | 475 | return self.unmanaged.keyIterator(); |
| 476 | } | 476 | } |
| 477 | | 477 | |
| 478 | /// Create an iterator over the values in the map. | 478 | /// Create an iterator over the values in the map. |
| 479 | /// The iterator is invalidated if the map is modified. | 479 | /// The iterator is invalidated if the map is modified. |
| 480 | pub fn valueIterator(self: *const Self) ValueIterator { | 480 | pub fn valueIterator(self: Self) ValueIterator { |
| 481 | return self.unmanaged.valueIterator(); | 481 | return self.unmanaged.valueIterator(); |
| 482 | } | 482 | } |
| 483 | | 483 | |
| ... | @@ -542,7 +542,7 @@ pub fn HashMap( | ... | @@ -542,7 +542,7 @@ pub fn HashMap( |
| 542 | | 542 | |
| 543 | /// Returns the number of total elements which may be present before it is | 543 | /// Returns the number of total elements which may be present before it is |
| 544 | /// no longer guaranteed that no allocations will be performed. | 544 | /// no longer guaranteed that no allocations will be performed. |
| 545 | pub fn capacity(self: *Self) Size { | 545 | pub fn capacity(self: Self) Size { |
| 546 | return self.unmanaged.capacity(); | 546 | return self.unmanaged.capacity(); |
| 547 | } | 547 | } |
| 548 | | 548 | |
| ... | @@ -977,23 +977,23 @@ pub fn HashMapUnmanaged( | ... | @@ -977,23 +977,23 @@ pub fn HashMapUnmanaged( |
| 977 | self.available = 0; | 977 | self.available = 0; |
| 978 | } | 978 | } |
| 979 | | 979 | |
| 980 | pub fn count(self: *const Self) Size { | 980 | pub fn count(self: Self) Size { |
| 981 | return self.size; | 981 | return self.size; |
| 982 | } | 982 | } |
| 983 | | 983 | |
| 984 | fn header(self: *const Self) *Header { | 984 | fn header(self: Self) *Header { |
| 985 | return @ptrCast(@as([*]Header, @ptrCast(@alignCast(self.metadata.?))) - 1); | 985 | return @ptrCast(@as([*]Header, @ptrCast(@alignCast(self.metadata.?))) - 1); |
| 986 | } | 986 | } |
| 987 | | 987 | |
| 988 | fn keys(self: *const Self) [*]K { | 988 | fn keys(self: Self) [*]K { |
| 989 | return self.header().keys; | 989 | return self.header().keys; |
| 990 | } | 990 | } |
| 991 | | 991 | |
| 992 | fn values(self: *const Self) [*]V { | 992 | fn values(self: Self) [*]V { |
| 993 | return self.header().values; | 993 | return self.header().values; |
| 994 | } | 994 | } |
| 995 | | 995 | |
| 996 | pub fn capacity(self: *const Self) Size { | 996 | pub fn capacity(self: Self) Size { |
| 997 | if (self.metadata == null) return 0; | 997 | if (self.metadata == null) return 0; |
| 998 | | 998 | |
| 999 | return self.header().capacity; | 999 | return self.header().capacity; |
| ... | @@ -1003,7 +1003,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1003,7 +1003,7 @@ pub fn HashMapUnmanaged( |
| 1003 | return .{ .hm = self }; | 1003 | return .{ .hm = self }; |
| 1004 | } | 1004 | } |
| 1005 | | 1005 | |
| 1006 | pub fn keyIterator(self: *const Self) KeyIterator { | 1006 | pub fn keyIterator(self: Self) KeyIterator { |
| 1007 | if (self.metadata) |metadata| { | 1007 | if (self.metadata) |metadata| { |
| 1008 | return .{ | 1008 | return .{ |
| 1009 | .len = self.capacity(), | 1009 | .len = self.capacity(), |
| ... | @@ -1019,7 +1019,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1019,7 +1019,7 @@ pub fn HashMapUnmanaged( |
| 1019 | } | 1019 | } |
| 1020 | } | 1020 | } |
| 1021 | | 1021 | |
| 1022 | pub fn valueIterator(self: *const Self) ValueIterator { | 1022 | pub fn valueIterator(self: Self) ValueIterator { |
| 1023 | if (self.metadata) |metadata| { | 1023 | if (self.metadata) |metadata| { |
| 1024 | return .{ | 1024 | return .{ |
| 1025 | .len = self.capacity(), | 1025 | .len = self.capacity(), |
| ... | @@ -1439,15 +1439,15 @@ pub fn HashMapUnmanaged( | ... | @@ -1439,15 +1439,15 @@ pub fn HashMapUnmanaged( |
| 1439 | } | 1439 | } |
| 1440 | | 1440 | |
| 1441 | /// Return true if there is a value associated with key in the map. | 1441 | /// Return true if there is a value associated with key in the map. |
| 1442 | pub fn contains(self: *const Self, key: K) bool { | 1442 | pub fn contains(self: Self, key: K) bool { |
| 1443 | if (@sizeOf(Context) != 0) | 1443 | if (@sizeOf(Context) != 0) |
| 1444 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call containsContext instead."); | 1444 | @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call containsContext instead."); |
| 1445 | return self.containsContext(key, undefined); | 1445 | return self.containsContext(key, undefined); |
| 1446 | } | 1446 | } |
| 1447 | pub fn containsContext(self: *const Self, key: K, ctx: Context) bool { | 1447 | pub fn containsContext(self: Self, key: K, ctx: Context) bool { |
| 1448 | return self.containsAdapted(key, ctx); | 1448 | return self.containsAdapted(key, ctx); |
| 1449 | } | 1449 | } |
| 1450 | pub fn containsAdapted(self: *const Self, key: anytype, ctx: anytype) bool { | 1450 | pub fn containsAdapted(self: Self, key: anytype, ctx: anytype) bool { |
| 1451 | return self.getIndex(key, ctx) != null; | 1451 | return self.getIndex(key, ctx) != null; |
| 1452 | } | 1452 | } |
| 1453 | | 1453 | |
| ... | @@ -1501,7 +1501,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1501,7 +1501,7 @@ pub fn HashMapUnmanaged( |
| 1501 | | 1501 | |
| 1502 | // This counts the number of occupied slots (not counting tombstones), which is | 1502 | // This counts the number of occupied slots (not counting tombstones), which is |
| 1503 | // what has to stay under the max_load_percentage of capacity. | 1503 | // what has to stay under the max_load_percentage of capacity. |
| 1504 | fn load(self: *const Self) Size { | 1504 | fn load(self: Self) Size { |
| 1505 | const max_load = (self.capacity() * max_load_percentage) / 100; | 1505 | const max_load = (self.capacity() * max_load_percentage) / 100; |
| 1506 | assert(max_load >= self.available); | 1506 | assert(max_load >= self.available); |
| 1507 | return @as(Size, @truncate(max_load - self.available)); | 1507 | return @as(Size, @truncate(max_load - self.available)); |
| ... | @@ -1603,19 +1603,19 @@ pub fn HashMapUnmanaged( | ... | @@ -1603,19 +1603,19 @@ pub fn HashMapUnmanaged( |
| 1603 | const total_size = std.mem.alignForward(usize, vals_end, max_align); | 1603 | const total_size = std.mem.alignForward(usize, vals_end, max_align); |
| 1604 | | 1604 | |
| 1605 | const slice = try allocator.alignedAlloc(u8, max_align, total_size); | 1605 | const slice = try allocator.alignedAlloc(u8, max_align, total_size); |
| 1606 | const ptr = @intFromPtr(slice.ptr); | 1606 | const ptr: [*]u8 = @ptrCast(slice.ptr); |
| 1607 | | 1607 | |
| 1608 | const metadata = ptr + @sizeOf(Header); | 1608 | const metadata = ptr + @sizeOf(Header); |
| 1609 | | 1609 | |
| 1610 | const hdr = @as(*Header, @ptrFromInt(ptr)); | 1610 | const hdr = @as(*Header, @ptrCast(@alignCast(ptr))); |
| 1611 | if (@sizeOf([*]V) != 0) { | 1611 | if (@sizeOf([*]V) != 0) { |
| 1612 | hdr.values = @as([*]V, @ptrFromInt(ptr + vals_start)); | 1612 | hdr.values = @ptrCast(@alignCast((ptr + vals_start))); |
| 1613 | } | 1613 | } |
| 1614 | if (@sizeOf([*]K) != 0) { | 1614 | if (@sizeOf([*]K) != 0) { |
| 1615 | hdr.keys = @as([*]K, @ptrFromInt(ptr + keys_start)); | 1615 | hdr.keys = @ptrCast(@alignCast((ptr + keys_start))); |
| 1616 | } | 1616 | } |
| 1617 | hdr.capacity = new_capacity; | 1617 | hdr.capacity = new_capacity; |
| 1618 | self.metadata = @as([*]Metadata, @ptrFromInt(metadata)); | 1618 | self.metadata = @ptrCast(@alignCast(metadata)); |
| 1619 | } | 1619 | } |
| 1620 | | 1620 | |
| 1621 | fn deallocate(self: *Self, allocator: Allocator) void { | 1621 | fn deallocate(self: *Self, allocator: Allocator) void { |
| ... | @@ -1638,7 +1638,7 @@ pub fn HashMapUnmanaged( | ... | @@ -1638,7 +1638,7 @@ pub fn HashMapUnmanaged( |
| 1638 | | 1638 | |
| 1639 | const total_size = std.mem.alignForward(usize, vals_end, max_align); | 1639 | const total_size = std.mem.alignForward(usize, vals_end, max_align); |
| 1640 | | 1640 | |
| 1641 | const slice = @as([*]align(max_align) u8, @ptrFromInt(@intFromPtr(self.header())))[0..total_size]; | 1641 | const slice = @as([*]align(max_align) u8, @alignCast(@ptrCast(self.header())))[0..total_size]; |
| 1642 | allocator.free(slice); | 1642 | allocator.free(slice); |
| 1643 | | 1643 | |
| 1644 | self.metadata = null; | 1644 | self.metadata = null; |