This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: number of calls to hash function in unordered_set
- From: Frank Tetzel <s1445051 at mail dot zih dot tu-dresden dot de>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 12 Jun 2018 09:48:39 +0200
- Subject: Re: number of calls to hash function in unordered_set
- References: <20180611182456.1b1a3468@archvm> <alpine.DEB.2.21.1806111938490.15614@stedding.saclay.inria.fr>
> > It seems to always be (inserted_elements * 2) - 1.
> > When adding 2 elements, it hashes 3 times. When adding 1 element, it
> > only hashes once. What is happening here? Why is the hash calculated
> > twice? What is so special about the last or first element?
>
> https://gcc.gnu.org/onlinedocs/libstdc++/manual/unordered_associative.html#containers.unordered.cache
> answers part of the question (libc++ on the other hand seems to have
> chosen always to cache the hash).
>
> The other part is related to how the elements are linked in the hash
> table, note that the hashes computed are 0 1 0 2 1 3 2 4 3 5 4 6 5 7
> 6... Reading the code seems best to understand what is going on.
>
Thank you for the link to the documentation. That also explains why
removing "noexcept" on the hash function enables caching.
I will try to step through the code and understand it. Reading STL is
always not so easy...
Thanks for the pointers.