Requirements for Hashes in Hashbrown HashMaps?

I just read this in a comment in the hecs code:

Because TypeId is already a fully-hashed u64 (including data in the high seven bits,
which hashbrown needs
), there is no need to hash it again. Instead, this uses the much
faster no-op hash.

Does that mean that if I were to have a hash that doesn't have any bits in the last 7 bits that it wouldn't work with std::collections::HashMap? Is this limit documented somewhere?

I was considering storing a type that I had overridden the hash to just return the internal u64 ID, but I wasn't aware that there were limits on what the hash should contain. Like is a small number like 23 invalid for some reason? It might not make a difference in my case as the number will probably be a hash anyway.

This reddit comment explains how hashbrown uses the high and low bits of the hash. It sounds like the high 7 bits are important in cases where there is a collision in the lower 57 bits modulo the size of the index table.

1 Like