From b9de2e99a33cc07587fe715a0329974578fcfc9e Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 8 Jun 2021 15:07:04 +0800 Subject: [PATCH] Actually hashing entries for a hash map makes it immensely faster --- nel/include/nel/misc/entity_id.h | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/nel/include/nel/misc/entity_id.h b/nel/include/nel/misc/entity_id.h index 61bbe1ef4..584891219 100644 --- a/nel/include/nel/misc/entity_id.h +++ b/nel/include/nel/misc/entity_id.h @@ -25,6 +25,7 @@ #include "debug.h" #include "common.h" #include "stream.h" +#include "wang_hash.h" namespace NLMISC { @@ -577,6 +578,7 @@ public: };*/ // Traits for hash_map using CEntityId +#if 0 struct CEntityIdHashMapTraits { enum { bucket_size = 4, min_buckets = 8 }; @@ -596,7 +598,27 @@ struct CEntityIdHashMapTraits return id1.getShortId() < id2.getShortId(); } }; - +#else +struct CEntityIdHashMapTraits +{ + enum { bucket_size = 4, min_buckets = 8 }; + CEntityIdHashMapTraits() { } + size_t operator() (const NLMISC::CEntityId &id ) const + { + uint64 hash64 = id.getUniqueId(); + if (sizeof(size_t) == 8) + { + return (size_t)NLMISC::wangHash64(hash64); + } + else + { + uint32 hash32a = NLMISC::wangHash((uint32)(hash64 & 0xFFFFFFFF)); + uint32 hash32b = NLMISC::wangHash((uint32)(hash64 >> 32)); + return hash32a ^ hash32b; + } + } +}; +#endif /*inline std::stringstream &operator << (std::stringstream &__os, const CEntityId &__t) {