Problem
When creating a KnownKey, the hash builder is discarded:
In order to ensure that the hash is going to be the same later on, the hash builder used for the pre-calculated hash (i.e., the screenshot) must be the same one from whatever hash map is being used. Some hashing algorithms start with a random seed, so if their hash builder isn't reused they return different hashes.
We currently use halfbrown's hash builder, which is deterministic and is why everything works right now. But it seems somewhat wrong to rely on a deterministic hash builder with no warning whatsoever.
Steps
Possible Solution(s)
- Proper fix: restructure
KnownKeyso that we are guaranteed that the hash builder is going to be the same. We currently construct them with aFrom<Cow>. To fix this, we could either have a constructor that takesCow, HashBuilder, or that initizalizes theHashBuilderitself and returns it in the constructor, too. That way it can be reused with the hash map. There may be another better solution which enforces this statically, since one could always forget to reuse it manually. - Realistic fix: continue using the current
KnownKeyimplementation if there are no plans to change the hashing algorithm. But there should be at least a warning inKnownKeyso that noone changes it, explaining this issue. We could also enforcehalfbrown::DefaultHashBuilderin the parameters ofKnownKey's methods, which should at least emit compile-time warnings.
