-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Description
With HashMaps of capacity of 58 or greater it is possible to have a length which is larger than the reported capacity. Here's a test which demonstrates the problem:
#![feature(core)]
use std::collections::HashMap;
fn find_broken(size: usize) {
let mut a: HashMap<usize, usize> = HashMap::with_capacity(size);
// Fill the hashmap up to its capacity
for i in range(0, a.capacity()) {
a.insert(i, i);
}
// Add one more element. Should reallocate in theory.
let cap = a.capacity();
a.insert(cap, cap);
if a.len() > a.capacity() {
// OMGWTF?!?!?
println!("{} {} {}", size, a.len(), a.capacity());
}
}
fn main() {
for i in range(0, 255) {
find_broken(i);
}
}
rustc version:
rustc 1.0.0-nightly (4be79d6ac 2015-01-23 16:08:14 +0000)
binary: rustc
commit-hash: 4be79d6acde9eed3a9b5281a46f385bcb4ce736c
commit-date: 2015-01-23 16:08:14 +0000
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly
Metadata
Metadata
Assignees
Labels
No labels