You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FxHasher can currently only be created with the 0 value for hash. It would be useful to have a constructor that constructs it with the explicitly provided seed.
As described in #14, certain operations on FxHashMap could be made faster by making the map unstable, i.e. changing the seed of the hash function for each new map. However, rustc_hash::FxHasher doesn't offer a way to create the hasher with the specified initial hash value. As a workaround, we can use write_u32() to modify the value:
// BuildHasherRandom is created with random state, like RandomState in the// stlib - https://bit.ly/39pEvnN#[derive(Debug,Clone)]structBuildHasherRandom(u32);implBuildHasherforBuildHasherRandom{typeHasher = FxHasher;fnbuild_hasher(&self) -> FxHasher{// workaround: create `FxHasher` with the random seed from self.0letmut hasher = FxHasher::default();
hasher.write_u32(self.0);
hasher
}}
It's not obvious that the compiler is able to optimize write_u32(n) with a known starting value of hasher.hash. Ideally build_hasher() should be able to explicitly provide the seed to the FxHasher constructor, such as:
Note that we need from_seed only to implement randomization to fix #14. If an equivalent of RandomState were built into rustc_hash, we would no longer need the from_seed functionality.
The text was updated successfully, but these errors were encountered:
FxHasher
can currently only be created with the 0 value forhash
. It would be useful to have a constructor that constructs it with the explicitly provided seed.As described in #14, certain operations on
FxHashMap
could be made faster by making the map unstable, i.e. changing the seed of the hash function for each new map. However,rustc_hash::FxHasher
doesn't offer a way to create the hasher with the specified initial hash value. As a workaround, we can usewrite_u32()
to modify the value:It's not obvious that the compiler is able to optimize
write_u32(n)
with a known starting value ofhasher.hash
. Ideallybuild_hasher()
should be able to explicitly provide the seed to theFxHasher
constructor, such as:Note that we need
from_seed
only to implement randomization to fix #14. If an equivalent ofRandomState
were built intorustc_hash
, we would no longer need thefrom_seed
functionality.The text was updated successfully, but these errors were encountered: