| ... | ... | @@ -1351,7 +1351,7 @@ pub fn ArrayHashMapUnmanaged( |
| 1351 | 1351 | pub fn setKeyContext(self: *Self, gpa: Allocator, index: usize, new_key: K, ctx: Context) Oom!void { |
| 1352 | 1352 | const key_ptr = &self.entries.items(.key)[index]; |
| 1353 | 1353 | key_ptr.* = new_key; |
| 1354 | | if (store_hash) self.entries.items(.hash)[index].* = checkedHash(ctx, key_ptr.*); |
| 1354 | if (store_hash) self.entries.items(.hash)[index] = checkedHash(ctx, key_ptr.*); |
| 1355 | 1355 | try rebuildIndex(self, gpa, undefined); |
| 1356 | 1356 | } |
| 1357 | 1357 | |
| ... | ... | @@ -2550,10 +2550,26 @@ test "0 sized key and 0 sized value" { |
| 2550 | 2550 | try testing.expectEqual(map.get(0), null); |
| 2551 | 2551 | } |
| 2552 | 2552 | |
| 2553 | | test "setKey" { |
| 2553 | test "setKey storehash true" { |
| 2554 | 2554 | const gpa = std.testing.allocator; |
| 2555 | 2555 | |
| 2556 | | var map: AutoArrayHashMapUnmanaged(i32, i32) = .empty; |
| 2556 | var map: ArrayHashMapUnmanaged(i32, i32, AutoContext(i32), true) = .empty; |
| 2557 | defer map.deinit(gpa); |
| 2558 | |
| 2559 | try map.put(gpa, 12, 34); |
| 2560 | try map.put(gpa, 56, 78); |
| 2561 | |
| 2562 | try map.setKey(gpa, 0, 42); |
| 2563 | try testing.expectEqual(2, map.count()); |
| 2564 | try testing.expectEqual(false, map.contains(12)); |
| 2565 | try testing.expectEqual(34, map.get(42)); |
| 2566 | try testing.expectEqual(78, map.get(56)); |
| 2567 | } |
| 2568 | |
| 2569 | test "setKey storehash false" { |
| 2570 | const gpa = std.testing.allocator; |
| 2571 | |
| 2572 | var map: ArrayHashMapUnmanaged(i32, i32, AutoContext(i32), false) = .empty; |
| 2557 | 2573 | defer map.deinit(gpa); |
| 2558 | 2574 | |
| 2559 | 2575 | try map.put(gpa, 12, 34); |