More generic hash function for FSM

The hash function introduced in 6faf704731 doesn't work on 32 bit
systems. This one should.

Accepted By: @vladislavbelov
Differential Revision: https://code.wildfiregames.com/D5237
This was SVN commit r28033.
This commit is contained in:
phosit 2024-02-16 17:31:40 +00:00
parent c1d7ac6182
commit 483da49759

View File

@ -170,10 +170,10 @@ private:
{ {
size_t operator()(const TransitionKey& key) const noexcept size_t operator()(const TransitionKey& key) const noexcept
{ {
static_assert(sizeof(UnderlyingType) <= sizeof(size_t) / 2); constexpr size_t count{std::numeric_limits<size_t>::digits / 2};
return (static_cast<size_t>(key.state) << const size_t wideState{static_cast<size_t>(key.state)};
((sizeof(size_t) / 2) * std::numeric_limits<unsigned char>::digits)) + const size_t rotatedState{(wideState << count) | (wideState >> count)};
static_cast<size_t>(key.eventType); return static_cast<size_t>(key.eventType) ^ rotatedState;
} }
}; };