MultiArrayList: Fix error when struct is 0 sized

Also fixes error with ArrayHashMap when both key and value are 0 sized
This commit is contained in:
riverbl
2022-01-24 15:31:27 +00:00
committed by GitHub
parent c54a7ca4b2
commit 1f10cf4edf
2 changed files with 86 additions and 6 deletions

View File

@@ -2215,6 +2215,35 @@ test "auto store_hash" {
try testing.expect(meta.fieldInfo(HasExpensiveEqlUn.Data, .hash).field_type != void);
}
test "0 sized key" {
var map = AutoArrayHashMap(u0, i32).init(std.testing.allocator);
defer map.deinit();
try testing.expectEqual(map.get(0), null);
try map.put(0, 5);
try testing.expectEqual(map.get(0), 5);
try map.put(0, 10);
try testing.expectEqual(map.get(0), 10);
try testing.expectEqual(map.swapRemove(0), true);
try testing.expectEqual(map.get(0), null);
}
test "0 sized key and 0 sized value" {
var map = AutoArrayHashMap(u0, u0).init(std.testing.allocator);
defer map.deinit();
try testing.expectEqual(map.get(0), null);
try map.put(0, 0);
try testing.expectEqual(map.get(0), 0);
try testing.expectEqual(map.swapRemove(0), true);
try testing.expectEqual(map.get(0), null);
}
pub fn getHashPtrAddrFn(comptime K: type, comptime Context: type) (fn (Context, K) u32) {
return struct {
fn hash(ctx: Context, key: K) u32 {