Skip to content
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

[Question] Should eastl::unordered_set.reserve not check if a change is required? #521

Open
ScottDennison opened this issue Sep 6, 2023 · 0 comments

Comments

@ScottDennison
Copy link

eastl::unordered_set is implemented behind the scenes as a eastl::hashtable

The various eastl colleciton classes support the method reserve to reserve enough space to hold data that is intended to be inserted, to prevent repeated allocations.
In most cases, a check is made to see if any allocations would actually need to be done, and if not, the method exits without making any changes.

eastl::hashtable on the otherhand blindly always calls rehash, which calls DoRehash, which always does allocations, copies and frees, even if the amount of buckets that were calculated as being needed is the same as before.
It also will happily accept reducing the amount of buckets if reserve was passed in a size that was less than the current size.

I herefore raise:

  1. Why does reserve() not bail out if the size provided is less than or equal to the current size.
  2. Why does reserve() also not bail out if, while the size provided is greater than the current size, there is no change required to the number of buckets, and therefore no reallocations required.

I have opened this as a question as opposed to providing a pull request, as I am primarily a Java developer and therefore don't consider myself knowledgeable with EASTL enough to know if there is a valid reason for this behaviour to exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant