From 7624eceff08867516a8d33376852fe3794c8d6df Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Sun, 30 Dec 2018 12:04:53 +0700 Subject: [PATCH] hash_combine for entity and const_entity std::hash specializations --- ecs.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ecs.hpp b/ecs.hpp index d72c9f4..57c57fc 100644 --- a/ecs.hpp +++ b/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 { std::size_t operator()(const ecs_hpp::entity& ent) const noexcept { - return std::hash()(ent.id()); + return ecs_hpp::detail::hash_combine( + std::hash()(&ent.owner()), + std::hash()(ent.id())); } }; } @@ -750,7 +760,9 @@ namespace std : std::unary_function { std::size_t operator()(const ecs_hpp::const_entity& ent) const noexcept { - return std::hash()(ent.id()); + return ecs_hpp::detail::hash_combine( + std::hash()(&ent.owner()), + std::hash()(ent.id())); } }; }