From 17e18940349acc4eb791a6856a578271ee0d119a Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Tue, 12 Feb 2019 20:23:01 +0100 Subject: [PATCH] Add specialized string key for hash map. --- server/TracyCharUtil.hpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/server/TracyCharUtil.hpp b/server/TracyCharUtil.hpp index 8dd777fd..8b09f3bf 100644 --- a/server/TracyCharUtil.hpp +++ b/server/TracyCharUtil.hpp @@ -69,6 +69,33 @@ struct LessComparator } }; +struct StringKey +{ + const char* ptr; + size_t sz; + + struct Hasher + { + size_t operator()( const StringKey& key ) const + { + return hash( key.ptr, key.sz ); + } + }; + + struct HasherPOT : public Hasher + { + typedef tracy::power_of_two_hash_policy hash_policy; + }; + + struct Comparator + { + bool operator()( const StringKey& lhs, const StringKey& rhs ) const + { + return lhs.sz == rhs.sz && memcmp( lhs.ptr, rhs.ptr, lhs.sz ) == 0; + } + }; +}; + } }