[LLVMdev] ADT/Hashing.h on 32-bit platforms
Stephan Tolksdorf
st at quanttec.com
Mon Feb 3 15:39:08 PST 2014
On 14-02-03 23:05, Chandler Carruth wrote:
>
> Very cool. A minor comment:
Thanks!
>
> /// \brief Form a hash code directly from a numerical value.
> - hash_code(size_t value) : value(value) {}
> + ///
> + /// The argument is casted to and stored as a size_t value.
> + hash_code(uint64_t value) : value(static_cast<size_t>(value)) {}
>
> I think it would be better to store the 64-bit value internally and
> reduce to size_t when asked. That way we could (perhaps in the future)
> expose a higher fidelity uint64_t extraction mechanism.
>
> My idea is basically that the hashing code should be 64-bit input
> always, and 64-bit output always, but provide easy methods for consumers
> which *need* to only get size_t output to truncate safely and consistently.
>
> Does that make sense?
Making hash_code 64-bit would definitely be conceptually cleaner.
But I'd be a bit worried that users might directly store `hash_code`
values in their data structures, e.g. in hash table buckets, which
probably would be a pessimization on 32-bit systems for most use cases.
Do you have a good application in mind for an unstable non-cryptographic
64-bit hash code on a 32-bit system?
- Stephan
More information about the llvm-dev
mailing list