forked from 0ad/0ad
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:
parent
c1d7ac6182
commit
483da49759
@ -170,10 +170,10 @@ private:
|
||||
{
|
||||
size_t operator()(const TransitionKey& key) const noexcept
|
||||
{
|
||||
static_assert(sizeof(UnderlyingType) <= sizeof(size_t) / 2);
|
||||
return (static_cast<size_t>(key.state) <<
|
||||
((sizeof(size_t) / 2) * std::numeric_limits<unsigned char>::digits)) +
|
||||
static_cast<size_t>(key.eventType);
|
||||
constexpr size_t count{std::numeric_limits<size_t>::digits / 2};
|
||||
const size_t wideState{static_cast<size_t>(key.state)};
|
||||
const size_t rotatedState{(wideState << count) | (wideState >> count)};
|
||||
return static_cast<size_t>(key.eventType) ^ rotatedState;
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user