Closed
Description
The documentation for HashMap::capacity()
says:
Returns the number of elements the map can hold without reallocating.
However, a HashMap
will sometimes store more elements than its capacity indicates. See this example (Playpen link):
use std::collections::HashMap;
fn main() {
let mut map = HashMap::new();
for i in 0..1000 {
map.insert(i, i);
let (cap, len) = (map.capacity(), map.len());
assert!(cap >= len, "cap {} len {}", cap, len);
}
}
Metadata
Metadata
Assignees
Labels
No labels