summaryrefslogtreecommitdiff
path: root/source/core/hash.h
diff options
context:
space:
mode:
authorTim Foley <tfoley@nvidia.com>2017-06-15 13:24:25 -0700
committerTim Foley <tfoley@nvidia.com>2017-06-15 13:24:25 -0700
commit205187b561c3b31fa931e73e8f7263f0c4b1de41 (patch)
tree7bd2cd5ae3c14416b71ef8319ff02ace429d1132 /source/core/hash.h
parent517513645afb8eaf4841e7b7035f1ba3a9c7cd57 (diff)
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.
Diffstat (limited to 'source/core/hash.h')
-rw-r--r--source/core/hash.h156
1 files changed, 76 insertions, 80 deletions
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 <string.h>
-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<const char *>(buffer));
}
+ return hash;
+ }
+ inline int GetHashCode(char * buffer)
+ {
+ return GetHashCode(const_cast<const char *>(buffer));
+ }
- template<int IsInt>
- class Hash
- {
- public:
- };
- template<>
- class Hash<1>
- {
- public:
- template<typename TKey>
- static int GetHashCode(TKey & key)
- {
- return (int)key;
- }
- };
- template<>
- class Hash<0>
- {
- public:
- template<typename TKey>
- static int GetHashCode(TKey & key)
- {
- return key.GetHashCode();
- }
- };
- template<int IsPointer>
- class PointerHash
- {};
- template<>
- class PointerHash<1>
+ template<int IsInt>
+ class Hash
+ {
+ public:
+ };
+ template<>
+ class Hash<1>
+ {
+ public:
+ template<typename TKey>
+ static int GetHashCode(TKey & key)
{
- public:
- template<typename TKey>
- static int GetHashCode(TKey const& key)
- {
- return (int)((CoreLib::PtrInt)key) / 16; // sizeof(typename std::remove_pointer<TKey>::type);
- }
- };
- template<>
- class PointerHash<0>
+ return (int)key;
+ }
+ };
+ template<>
+ class Hash<0>
+ {
+ public:
+ template<typename TKey>
+ static int GetHashCode(TKey & key)
{
- public:
- template<typename TKey>
- static int GetHashCode(TKey & key)
- {
- return Hash<std::is_integral<TKey>::value || std::is_enum<TKey>::value>::GetHashCode(key);
- }
- };
-
+ return key.GetHashCode();
+ }
+ };
+ template<int IsPointer>
+ class PointerHash
+ {};
+ template<>
+ class PointerHash<1>
+ {
+ public:
template<typename TKey>
- int GetHashCode(const TKey & key)
+ static int GetHashCode(TKey const& key)
{
- return PointerHash<std::is_pointer<TKey>::value>::GetHashCode(key);
+ return (int)((PtrInt)key) / 16; // sizeof(typename std::remove_pointer<TKey>::type);
}
-
+ };
+ template<>
+ class PointerHash<0>
+ {
+ public:
template<typename TKey>
- int GetHashCode(TKey & key)
+ static int GetHashCode(TKey & key)
{
- return PointerHash<std::is_pointer<TKey>::value>::GetHashCode(key);
+ return Hash<std::is_integral<TKey>::value || std::is_enum<TKey>::value>::GetHashCode(key);
}
+ };
-
+ template<typename TKey>
+ int GetHashCode(const TKey & key)
+ {
+ return PointerHash<std::is_pointer<TKey>::value>::GetHashCode(key);
+ }
+
+ template<typename TKey>
+ int GetHashCode(TKey & key)
+ {
+ return PointerHash<std::is_pointer<TKey>::value>::GetHashCode(key);
}
+
+
}
#endif \ No newline at end of file