| ... | ... | @@ -687,8 +687,9 @@ pub fn ArrayHashMapUnmanaged( |
| 687 | 687 | |
| 688 | 688 | /// Removes the last inserted `Entry` in the hash map and returns it. |
| 689 | 689 | pub fn pop(self: *Self) Entry { |
| 690 | | const top = self.entries.pop(); |
| 690 | const top = self.entries.items[self.entries.items.len - 1]; |
| 691 | 691 | _ = self.removeWithHash(top.key, top.hash, .index_only); |
| 692 | self.entries.items.len -= 1; |
| 692 | 693 | return top; |
| 693 | 694 | } |
| 694 | 695 | |
| ... | ... | @@ -1258,19 +1259,18 @@ test "pop" { |
| 1258 | 1259 | var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator); |
| 1259 | 1260 | defer map.deinit(); |
| 1260 | 1261 | |
| 1261 | | testing.expect((try map.fetchPut(1, 11)) == null); |
| 1262 | | testing.expect((try map.fetchPut(2, 22)) == null); |
| 1263 | | testing.expect((try map.fetchPut(3, 33)) == null); |
| 1264 | | testing.expect((try map.fetchPut(4, 44)) == null); |
| 1262 | // Insert just enough entries so that the map expands. Afterwards, |
| 1263 | // pop all entries out of the map. |
| 1265 | 1264 | |
| 1266 | | const pop1 = map.pop(); |
| 1267 | | testing.expect(pop1.key == 4 and pop1.value == 44); |
| 1268 | | const pop2 = map.pop(); |
| 1269 | | testing.expect(pop2.key == 3 and pop2.value == 33); |
| 1270 | | const pop3 = map.pop(); |
| 1271 | | testing.expect(pop3.key == 2 and pop3.value == 22); |
| 1272 | | const pop4 = map.pop(); |
| 1273 | | testing.expect(pop4.key == 1 and pop4.value == 11); |
| 1265 | var i: i32 = 0; |
| 1266 | while (i < 9) : (i += 1) { |
| 1267 | testing.expect((try map.fetchPut(i, i)) == null); |
| 1268 | } |
| 1269 | |
| 1270 | while (i > 0) : (i -= 1) { |
| 1271 | const pop = map.pop(); |
| 1272 | testing.expect(pop.key == i - 1 and pop.value == i - 1); |
| 1273 | } |
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | 1276 | test "reIndex" { |