Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/network/FSM.h
Show First 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | struct TransitionKey | ||||
using UnderlyingType = unsigned int; | using UnderlyingType = unsigned int; | ||||
UnderlyingType state; | UnderlyingType state; | ||||
UnderlyingType eventType; | UnderlyingType eventType; | ||||
struct Hash | struct Hash | ||||
{ | { | ||||
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; | ||||
} | } | ||||
}; | }; | ||||
friend bool operator==(const TransitionKey& lhs, const TransitionKey& rhs) noexcept | friend bool operator==(const TransitionKey& lhs, const TransitionKey& rhs) noexcept | ||||
{ | { | ||||
return lhs.state == rhs.state && lhs.eventType == rhs.eventType; | return lhs.state == rhs.state && lhs.eventType == rhs.eventType; | ||||
} | } | ||||
}; | }; | ||||
Show All 23 Lines |
Wildfire Games · Phabricator