| 1 | /* |
| 2 | * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * This library is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU Library General Public |
| 6 | * License as published by the Free Software Foundation; either |
| 7 | * version 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * This library is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 | * Library General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Library General Public License |
| 15 | * along with this library; see the file COPYING.LIB. If not, write to |
| 16 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 17 | * Boston, MA 02110-1301, USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #ifndef WTF_HashFunctions_h |
| 22 | #define WTF_HashFunctions_hcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/HashFunctions.h:22:9`! |
| 23 | |
| 24 | #include "RefPtr.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/RefPtr.h`/ |
| 25 | #include <stdint.h> |
| 26 | |
| 27 | namespace WTFcxx . . $ QTWTF/ { |
| 28 | |
| 29 | template<size_tcxx . . $ size_t# size> struct IntTypescxx . . $ QTWTF/IntTypes#; |
| 30 | template<> struct IntTypescxx . . $ QTWTF/IntTypes#<1> { typedef int8_tcxx . . $ int8_t# SignedTypecxx . . $ QTWTF/IntTypes#SignedType#; typedef uint8_tcxx . . $ uint8_t# UnsignedTypecxx . . $ QTWTF/IntTypes#UnsignedType#; }; |
| 31 | template<> struct IntTypescxx . . $ QTWTF/IntTypes#<2> { typedef int16_tcxx . . $ int16_t# SignedTypecxx . . $ QTWTF/IntTypes#SignedType#; typedef uint16_tcxx . . $ uint16_t# UnsignedTypecxx . . $ QTWTF/IntTypes#UnsignedType#; }; |
| 32 | template<> struct IntTypescxx . . $ QTWTF/IntTypes#<4> { typedef int32_tcxx . . $ int32_t# SignedTypecxx . . $ QTWTF/IntTypes#SignedType#; typedef uint32_tcxx . . $ uint32_t# UnsignedTypecxx . . $ QTWTF/IntTypes#UnsignedType#; }; |
| 33 | template<> struct IntTypescxx . . $ QTWTF/IntTypes#<8> { typedef int64_tcxx . . $ int64_t# SignedTypecxx . . $ QTWTF/IntTypes#SignedType#; typedef uint64_tcxx . . $ uint64_t# UnsignedTypecxx . . $ QTWTF/IntTypes#UnsignedType#; }; |
| 34 | |
| 35 | // integer hash function |
| 36 | |
| 37 | // Thomas Wang's 32 Bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
| 38 | inline unsigned intHashcxx . . $ QTWTF/intHash(ded9d4c05c7b1550).(uint8_tcxx . . $ uint8_t# key8) |
| 39 | { |
| 40 | unsigned key = key8; |
| 41 | key += ~(key << 15); |
| 42 | key ^= (key >> 10); |
| 43 | key += (key << 3); |
| 44 | key ^= (key >> 6); |
| 45 | key += ~(key << 11); |
| 46 | key ^= (key >> 16); |
| 47 | return key; |
| 48 | } |
| 49 | |
| 50 | // Thomas Wang's 32 Bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
| 51 | inline unsigned intHashcxx . . $ QTWTF/intHash(909d59720f161188).(uint16_tcxx . . $ uint16_t# key16) |
| 52 | { |
| 53 | unsigned key = key16; |
| 54 | key += ~(key << 15); |
| 55 | key ^= (key >> 10); |
| 56 | key += (key << 3); |
| 57 | key ^= (key >> 6); |
| 58 | key += ~(key << 11); |
| 59 | key ^= (key >> 16); |
| 60 | return key; |
| 61 | } |
| 62 | |
| 63 | // Thomas Wang's 32 Bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
| 64 | inline unsigned intHashcxx . . $ QTWTF/intHash(2141b656ce2cc063).(uint32_tcxx . . $ uint32_t# key) |
| 65 | { |
| 66 | key += ~(key << 15); |
| 67 | key ^= (key >> 10); |
| 68 | key += (key << 3); |
| 69 | key ^= (key >> 6); |
| 70 | key += ~(key << 11); |
| 71 | key ^= (key >> 16); |
| 72 | return key; |
| 73 | } |
| 74 | |
| 75 | // Thomas Wang's 64 bit Mix Function: http://www.cris.com/~Ttwang/tech/inthash.htm |
| 76 | inline unsigned intHashcxx . . $ QTWTF/intHash(ea88b852781e8a38).(uint64_tcxx . . $ uint64_t# key) |
| 77 | { |
| 78 | key += ~(key << 32); |
| 79 | key ^= (key >> 22); |
| 80 | key += ~(key << 13); |
| 81 | key ^= (key >> 8); |
| 82 | key += (key << 3); |
| 83 | key ^= (key >> 15); |
| 84 | key += ~(key << 27); |
| 85 | key ^= (key >> 31); |
| 86 | return static_cast<unsigned>(key); |
| 87 | } |
| 88 | |
| 89 | template<typename T> struct IntHashcxx . . $ QTWTF/IntHash# { |
| 90 | static unsigned hashcxx . . $ QTWTF/IntHash#hash(78ea24164916a3a1).(T key) { return intHashcxx . . $ QTWTF/intHash(2141b656ce2cc063).(static_cast<typename IntTypescxx . . $ QTWTF/IntTypes#<sizeof(T)>::UnsignedType>(key)); } |
| 91 | static bool equalcxx . . $ QTWTF/IntHash#equal(780fb9bd2d2dda6f).(T a, T b) { return a ==cxx . . $ QTWTF/`operator==`(69feba05d53a7241). b; } |
| 92 | static const bool safeToCompareToEmptyOrDeletedcxx . . $ QTWTF/IntHash#safeToCompareToEmptyOrDeleted. = true; |
| 93 | }; |
| 94 | |
| 95 | template<typename T> struct FloatHashcxx . . $ QTWTF/FloatHash# { |
| 96 | static unsigned hashcxx . . $ QTWTF/FloatHash#hash(78ea24164916a3a1).(T key) |
| 97 | { |
| 98 | unioncxx . . $ QTWTF/FloatHash#hash(78ea24164916a3a1).$anonymous_type_0# { |
| 99 | T keycxx . . $ QTWTF/FloatHash#hash(78ea24164916a3a1).$anonymous_type_0#key.; |
| 100 | typename IntTypescxx . . $ QTWTF/IntTypes#<sizeof(T)>::UnsignedType bitscxx . . $ QTWTF/FloatHash#hash(78ea24164916a3a1).$anonymous_type_0#bits.; |
| 101 | } u; |
| 102 | u.keycxx . . $ QTWTF/FloatHash#hash(78ea24164916a3a1).$anonymous_type_0#key. = key; |
| 103 | return intHashcxx . . $ QTWTF/intHash(ded9d4c05c7b1550).(u.bitscxx . . $ QTWTF/FloatHash#hash(78ea24164916a3a1).$anonymous_type_0#bits.); |
| 104 | } |
| 105 | static bool equalcxx . . $ QTWTF/FloatHash#equal(780fb9bd2d2dda6f).(T a, T b) { return a ==cxx . . $ QTWTF/`operator==`(e47811f5710122ad). b; } |
| 106 | static const bool safeToCompareToEmptyOrDeletedcxx . . $ QTWTF/FloatHash#safeToCompareToEmptyOrDeleted. = true; |
| 107 | }; |
| 108 | |
| 109 | // pointer identity hash function |
| 110 | |
| 111 | template<typename T> struct PtrHashcxx . . $ QTWTF/PtrHash# { |
| 112 | static unsigned hashcxx . . $ QTWTF/PtrHash#hash(78ea24164916a3a1).(T key) |
| 113 | { |
| 114 | #if COMPILERcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:39:9`!(MSVC) |
| 115 | #pragma warning(push) |
| 116 | #pragma warning(disable: 4244) // work around what seems to be a bug in MSVC's conversion warnings |
| 117 | #endif |
| 118 | return IntHash<uintptr_t>::hash(reinterpret_cast<uintptr_t>(key)); |
| 119 | #if COMPILERcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:39:9`!(MSVC) |
| 120 | #pragma warning(pop) |
| 121 | #endif |
| 122 | } |
| 123 | static bool equalcxx . . $ QTWTF/PtrHash#equal(780fb9bd2d2dda6f).(T a, T b) { return a ==cxx . . $ QTWTF/`operator==`(80d3fa33a1df3c2c). b; } |
| 124 | static const bool safeToCompareToEmptyOrDeletedcxx . . $ QTWTF/PtrHash#safeToCompareToEmptyOrDeleted. = true; |
| 125 | }; |
| 126 | template<typename P> struct PtrHashcxx . . $ QTWTF/PtrHash#<RefPtrcxx . . $ QTWTF/RefPtr#<P> > : PtrHashcxx . . $ QTWTF/PtrHash#<P*> { |
| 127 | using PtrHashcxx . . $ QTWTF/PtrHash#<P*>::hash; |
| 128 | static unsigned hashcxx . . $ QTWTF/PtrHash#hash(ddff102d1dfc5557).(const RefPtrcxx . . $ QTWTF/RefPtr#<P>& key) { return hashcxx . . $ QTWTF/PtrHash#hash(ddff102d1dfc5557).(key.getcxx . . $ QTWTF/RefPtr#get(5a2a78a048fb49a8).()); } |
| 129 | using PtrHashcxx . . $ QTWTF/PtrHash#<P*>::equal; |
| 130 | static bool equalcxx . . $ QTWTF/PtrHash#equal(9e37066f18a7dd23).(const RefPtrcxx . . $ QTWTF/RefPtr#<P>& a, const RefPtrcxx . . $ QTWTF/RefPtr#<P>& b) { return a ==cxx . . $ QTWTF/`operator==`(31369b2754de4004). b; } |
| 131 | static bool equalcxx . . $ QTWTF/PtrHash#equal(b70381f49ff8cff8).(P* a, const RefPtrcxx . . $ QTWTF/RefPtr#<P>& b) { return a ==cxx . . $ QTWTF/`operator==`(8bba44cd2316e962). b; } |
| 132 | static bool equalcxx . . $ QTWTF/PtrHash#equal(c14fc8843ac76aa9).(const RefPtrcxx . . $ QTWTF/RefPtr#<P>& a, P* b) { return a ==cxx . . $ QTWTF/`operator==`(80d3fa33a1df3c2c). b; } |
| 133 | }; |
| 134 | |
| 135 | // default hash function for each type |
| 136 | |
| 137 | template<typename T> struct DefaultHashcxx . . $ QTWTF/DefaultHash#; |
| 138 | |
| 139 | template<typename T, typename U> struct PairHashcxx . . $ QTWTF/PairHash# { |
| 140 | static unsigned hashcxx . . $ QTWTF/PairHash#hash(738ea01597486edb).(const stdcxx . . $ std/::paircxx . . $ std/pair#<T, U>& p) |
| 141 | { |
| 142 | return intHashcxx . . $ QTWTF/intHash(2141b656ce2cc063).((static_cast<uint64_tcxx . . $ uint64_t#>(DefaultHashcxx . . $ QTWTF/DefaultHash#<T>::Hash::hash(p.firstcxx . . $ std/pair#first.)) << 32 |cxx . . $ `operator|`(68626a7e09ca3b35). DefaultHashcxx . . $ QTWTF/DefaultHash#<U>::Hash::hash(p.secondcxx . . $ std/pair#second.))); |
| 143 | } |
| 144 | static bool equalcxx . . $ QTWTF/PairHash#equal(39b98f4fe21ae589).(const stdcxx . . $ std/::paircxx . . $ std/pair#<T, U>& a, const stdcxx . . $ std/::paircxx . . $ std/pair#<T, U>& b) |
| 145 | { |
| 146 | return DefaultHashcxx . . $ QTWTF/DefaultHash#<T>::Hash::equal(a.firstcxx . . $ std/pair#first., b.firstcxx . . $ std/pair#first.) && DefaultHashcxx . . $ QTWTF/DefaultHash#<U>::Hash::equal(a.secondcxx . . $ std/pair#second., b.secondcxx . . $ std/pair#second.); |
| 147 | } |
| 148 | static const bool safeToCompareToEmptyOrDeletedcxx . . $ QTWTF/PairHash#safeToCompareToEmptyOrDeleted. = DefaultHashcxx . . $ QTWTF/DefaultHash#<T>::Hash::safeToCompareToEmptyOrDeleted |
| 149 | && DefaultHashcxx . . $ QTWTF/DefaultHash#<U>::Hash::safeToCompareToEmptyOrDeleted; |
| 150 | }; |
| 151 | |
| 152 | // make IntHash the default hash function for many integer types |
| 153 | |
| 154 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<short> { typedef IntHashcxx . . $ QTWTF/IntHash#<unsigned> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 155 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<unsigned short> { typedef IntHashcxx . . $ QTWTF/IntHash#<unsigned> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 156 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<int> { typedef IntHashcxx . . $ QTWTF/IntHash#<unsigned> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 157 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<unsigned> { typedef IntHashcxx . . $ QTWTF/IntHash#<unsigned> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 158 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<long> { typedef IntHashcxx . . $ QTWTF/IntHash#<unsigned long> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 159 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<unsigned long> { typedef IntHashcxx . . $ QTWTF/IntHash#<unsigned long> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 160 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<long long> { typedef IntHashcxx . . $ QTWTF/IntHash#<unsigned long long> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 161 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<unsigned long long> { typedef IntHashcxx . . $ QTWTF/IntHash#<unsigned long long> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 162 | |
| 163 | #if !COMPILERcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/Platform.h:39:9`!(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED) |
| 164 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<wchar_t> { typedef IntHashcxx . . $ QTWTF/IntHash#<wchar_t> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 165 | #endif |
| 166 | |
| 167 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<float> { typedef FloatHashcxx . . $ QTWTF/FloatHash#<float> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 168 | template<> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<double> { typedef FloatHashcxx . . $ QTWTF/FloatHash#<double> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 169 | |
| 170 | // make PtrHash the default hash function for pointer types that don't specialize |
| 171 | |
| 172 | template<typename P> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<P*> { typedef PtrHashcxx . . $ QTWTF/PtrHash#<P*> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 173 | template<typename P> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<RefPtrcxx . . $ QTWTF/RefPtr#<P> > { typedef PtrHashcxx . . $ QTWTF/PtrHash#<RefPtrcxx . . $ QTWTF/RefPtr#<P> > Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 174 | |
| 175 | template<typename T, typename U> struct DefaultHashcxx . . $ QTWTF/DefaultHash#<stdcxx . . $ std/::paircxx . . $ std/pair#<T, U> > { typedef PairHashcxx . . $ QTWTF/PairHash#<T, U> Hashcxx . . $ QTWTF/DefaultHash#Hash#; }; |
| 176 | |
| 177 | } // namespace WTF |
| 178 | |
| 179 | using WTFcxx . . $ `<built-in>:467:9`!::DefaultHashcxx . . $ QTWTF/DefaultHash#; |
| 180 | using WTFcxx . . $ `<built-in>:467:9`!::IntHashcxx . . $ QTWTF/IntHash#; |
| 181 | using WTFcxx . . $ `<built-in>:467:9`!::PtrHashcxx . . $ QTWTF/PtrHash#; |
| 182 | |
| 183 | #endif // WTF_HashFunctions_h |