From 205187b561c3b31fa931e73e8f7263f0c4b1de41 Mon Sep 17 00:00:00 2001 From: Tim Foley Date: Thu, 15 Jun 2017 13:24:25 -0700 Subject: Rename `CoreLib::*` to `Slang` Getting rid of more namespace complexity and stripping things down to the basics. This also gets rid of some dead code in the "core" library. --- source/core/hash.h | 156 ++++++++++++++++++++++++++--------------------------- 1 file changed, 76 insertions(+), 80 deletions(-) (limited to 'source/core/hash.h') diff --git a/source/core/hash.h b/source/core/hash.h index 07327a415..07a14099b 100644 --- a/source/core/hash.h +++ b/source/core/hash.h @@ -4,102 +4,98 @@ #include "slang-math.h" #include -namespace CoreLib +namespace Slang { - namespace Basic + inline int GetHashCode(double key) { - - inline int GetHashCode(double key) - { - return FloatAsInt((float)key); - } - inline int GetHashCode(float key) - { - return FloatAsInt(key); - } - inline int GetHashCode(const char * buffer) + return FloatAsInt((float)key); + } + inline int GetHashCode(float key) + { + return FloatAsInt(key); + } + inline int GetHashCode(const char * buffer) + { + if (!buffer) + return 0; + int hash = 0; + int c; + auto str = buffer; + c = *str++; + while (c) { - if (!buffer) - return 0; - int hash = 0; - int c; - auto str = buffer; + hash = c + (hash << 6) + (hash << 16) - hash; c = *str++; - while (c) - { - hash = c + (hash << 6) + (hash << 16) - hash; - c = *str++; - } - return hash; - } - inline int GetHashCode(char * buffer) - { - return GetHashCode(const_cast(buffer)); } + return hash; + } + inline int GetHashCode(char * buffer) + { + return GetHashCode(const_cast(buffer)); + } - template - class Hash - { - public: - }; - template<> - class Hash<1> - { - public: - template - static int GetHashCode(TKey & key) - { - return (int)key; - } - }; - template<> - class Hash<0> - { - public: - template - static int GetHashCode(TKey & key) - { - return key.GetHashCode(); - } - }; - template - class PointerHash - {}; - template<> - class PointerHash<1> + template + class Hash + { + public: + }; + template<> + class Hash<1> + { + public: + template + static int GetHashCode(TKey & key) { - public: - template - static int GetHashCode(TKey const& key) - { - return (int)((CoreLib::PtrInt)key) / 16; // sizeof(typename std::remove_pointer::type); - } - }; - template<> - class PointerHash<0> + return (int)key; + } + }; + template<> + class Hash<0> + { + public: + template + static int GetHashCode(TKey & key) { - public: - template - static int GetHashCode(TKey & key) - { - return Hash::value || std::is_enum::value>::GetHashCode(key); - } - }; - + return key.GetHashCode(); + } + }; + template + class PointerHash + {}; + template<> + class PointerHash<1> + { + public: template - int GetHashCode(const TKey & key) + static int GetHashCode(TKey const& key) { - return PointerHash::value>::GetHashCode(key); + return (int)((PtrInt)key) / 16; // sizeof(typename std::remove_pointer::type); } - + }; + template<> + class PointerHash<0> + { + public: template - int GetHashCode(TKey & key) + static int GetHashCode(TKey & key) { - return PointerHash::value>::GetHashCode(key); + return Hash::value || std::is_enum::value>::GetHashCode(key); } + }; - + template + int GetHashCode(const TKey & key) + { + return PointerHash::value>::GetHashCode(key); + } + + template + int GetHashCode(TKey & key) + { + return PointerHash::value>::GetHashCode(key); } + + } #endif \ No newline at end of file -- cgit v1.2.3