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