-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IndexMap
sometimes reports a lower capacity after removing elements
#183
Comments
IndexMap
sometimes reports a lower capacity after shift_remove
-ing elementsIndexMap
sometimes reports a lower capacity after swap_remove
-ing elements
IndexMap
sometimes reports a lower capacity after swap_remove
-ing elementsIndexMap
sometimes reports a lower capacity after removing elements
This is an artifact of
|
Why does |
I think it's because those
Yes, that's true. If a new insertion lands on a We could potentially add some heuristics to |
OK, so I guess that means I shouldn't use |
Currently, the only guarantee about avoiding allocation is if you dynamically check the With hashbrown 0.11 (#181) we could add a method that internally uses |
In the meantime, maybe it would be good to add something to the documentation about this? I'm sure I'm not the only one confused about why the capacity can decrease over time. |
Adding docs seems like the sensible action to resolve this issue, for the rest we refer to hashbrown. |
Hashbrown's
We could say something like that, and perhaps also note that removal may cause that to decrease. |
@tesselode if you're interested, maybe you could comment on rust-lang/hashbrown#255 why you're concerned about this, and whether you think such a manual |
I made a small test script that adds and removes elements from an
IndexMap
:Sometimes, when the length of the map (left) decreases, the capacity (right) decreases as well.
From what I understand, the "capacity" is the total number of elements the map can hold in the chunk of memory it has allocated. If you add an item when the map is full, I would expect the capacity to increase as the map allocates more memory. I would never expect the capacity to decrease.
This behavior occurs with both
swap_remove_index
andshift_remove_index
.The text was updated successfully, but these errors were encountered: