mirror of
https://github.com/BlackMATov/ecs.hpp.git
synced 2025-12-13 10:35:39 +07:00
hash_combine for entity and const_entity std::hash specializations
This commit is contained in:
16
ecs.hpp
16
ecs.hpp
@@ -74,6 +74,14 @@ namespace ecs_hpp
|
||||
return t;
|
||||
}
|
||||
|
||||
//
|
||||
// hash_combine
|
||||
//
|
||||
|
||||
constexpr std::size_t hash_combine(std::size_t l, std::size_t r) noexcept {
|
||||
return l ^ (r + 0x9e3779b9 + (l << 6) + (l >> 2));
|
||||
}
|
||||
|
||||
//
|
||||
// tuple_tail
|
||||
//
|
||||
@@ -695,7 +703,9 @@ namespace std
|
||||
: std::unary_function<const ecs_hpp::entity&, std::size_t>
|
||||
{
|
||||
std::size_t operator()(const ecs_hpp::entity& ent) const noexcept {
|
||||
return std::hash<ecs_hpp::entity_id>()(ent.id());
|
||||
return ecs_hpp::detail::hash_combine(
|
||||
std::hash<const ecs_hpp::registry*>()(&ent.owner()),
|
||||
std::hash<ecs_hpp::entity_id>()(ent.id()));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -750,7 +760,9 @@ namespace std
|
||||
: std::unary_function<const ecs_hpp::const_entity&, std::size_t>
|
||||
{
|
||||
std::size_t operator()(const ecs_hpp::const_entity& ent) const noexcept {
|
||||
return std::hash<ecs_hpp::entity_id>()(ent.id());
|
||||
return ecs_hpp::detail::hash_combine(
|
||||
std::hash<const ecs_hpp::registry*>()(&ent.owner()),
|
||||
std::hash<ecs_hpp::entity_id>()(ent.id()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user