[PATCH][_Hashtable] Fix hash code cache usage
Florian Weimer
fweimer@redhat.com
Thu Mar 13 09:24:15 GMT 2025
* Jonathan Wakely:
> On Thu, 13 Mar 2025 at 06:50, Florian Weimer <fweimer@redhat.com> wrote:
>>
>> * François Dumont:
>>
>> > + // Get hash code for a node that comes from another _Hashtable.
>> > + // Reuse a cached hash code if the hash function is stateless,
>> > + // otherwise recalculate it using our own hash function.
>> > + __hash_code
>> > + _M_hash_code_ext(const __node_value_type& __from) const
>> > + {
>> > + if constexpr (__and_<__hash_cached, is_empty<_Hash>>::value)
>> > + return __from._M_hash_code;
>> > + else
>> > + return this->_M_hash_code(_ExtractKey{}(__from._M_v()));
>> > + }
>>
>> Does C++ support stateful hash functions? I don't think so, and I don't
>> see it documented as a GNU extension, either.
>
> It does, yes. That's why the hash function isn't required to be
> default constructible, and has to be stored in the container and why
> doing swap on two containers has to swap the hash functions as well.
Interesting. I have trouble reconciling this with the Cpp17Hash
requirement that “The value” h(k) “shall depend only on the argument k
for the duration of the program.”
Thanks,
Florian
More information about the Libstdc++
mailing list