std: fix HashMap.clearRetainingCapacity

master
Vexu 2020-11-11 14:05:43 +02:00
parent f70160f89c
commit ae6f3291c0
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
1 changed files with 6 additions and 1 deletions

View File

@ -428,7 +428,7 @@ pub fn HashMapUnmanaged(
if (self.metadata) |_| {
self.initMetadatas();
self.size = 0;
self.available = 0;
self.available = @truncate(u32, (self.capacity() * MaxLoadPercentage) / 100);
}
}
@ -864,6 +864,11 @@ test "std.hash_map clearRetainingCapacity" {
expectEqual(map.get(1).?, 1);
expectEqual(map.count(), 1);
map.clearRetainingCapacity();
map.putAssumeCapacity(1, 1);
expectEqual(map.get(1).?, 1);
expectEqual(map.count(), 1);
const cap = map.capacity();
expect(cap > 0);