| ... | ... | @@ -1271,7 +1271,7 @@ pub fn HashMapUnmanaged( |
| 1271 | 1271 | // map, which is assumed to exist as key_ptr must be valid. This |
| 1272 | 1272 | // item must be at index 0. |
| 1273 | 1273 | const idx = if (@sizeOf(K) > 0) |
| 1274 | | (key_ptr - self.keys()) |
| 1274 | @as([*]K, @ptrCast(key_ptr)) - self.keys() |
| 1275 | 1275 | else |
| 1276 | 1276 | 0; |
| 1277 | 1277 | |
| ... | ... | @@ -2175,3 +2175,22 @@ test "rehash" { |
| 2175 | 2175 | } |
| 2176 | 2176 | } |
| 2177 | 2177 | } |
| 2178 | |
| 2179 | test "removeByPtr, key is array" { |
| 2180 | const gpa = testing.allocator; |
| 2181 | |
| 2182 | var map: AutoHashMapUnmanaged([2]u32, u32) = .empty; |
| 2183 | defer map.deinit(gpa); |
| 2184 | |
| 2185 | const key: [2]u32 = .{ 1, 2 }; |
| 2186 | try map.put(gpa, key, 3); |
| 2187 | |
| 2188 | try expectEqual(1, map.count()); |
| 2189 | try expectEqual(3, map.get(key)); |
| 2190 | |
| 2191 | const key_ptr = map.getKeyPtr(key).?; |
| 2192 | map.removeByPtr(key_ptr); |
| 2193 | |
| 2194 | try expectEqual(0, map.count()); |
| 2195 | try expectEqual(null, map.get(key)); |
| 2196 | } |