| 1 | /* |
| 2 | * Copyright (C) 2005, 2006, 2007, 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_HashTraits_h |
| 22 | #define WTF_HashTraits_hcxx . . $ `src/3rdparty/javascriptcore/JavaScriptCore/wtf/HashTraits.h:22:9`! |
| 23 | |
| 24 | #include "HashFunctions.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/HashFunctions.h`/ |
| 25 | #include "TypeTraits.h"cxx . . $ `<file>/src/3rdparty/javascriptcore/JavaScriptCore/wtf/TypeTraits.h`/ |
| 26 | #include <utility> |
| 27 | #include <limits> |
| 28 | |
| 29 | namespace WTFcxx . . $ QTWTF/ { |
| 30 | |
| 31 | using stdcxx . . $ std/::paircxx . . $ std/pair#; |
| 32 | using stdcxx . . $ std/::make_pair; |
| 33 | |
| 34 | template<typename T> struct HashTraitscxx . . $ QTWTF/HashTraits#; |
| 35 | |
| 36 | template<bool isInteger, typename T> struct GenericHashTraitsBasecxx . . $ QTWTF/GenericHashTraitsBase#; |
| 37 | |
| 38 | template<typename T> struct GenericHashTraitsBasecxx . . $ QTWTF/GenericHashTraitsBase#<false, T> { |
| 39 | static const bool emptyValueIsZerocxx . . $ QTWTF/GenericHashTraitsBase#emptyValueIsZero. = false; |
| 40 | static const bool needsDestructioncxx . . $ QTWTF/GenericHashTraitsBase#needsDestruction. = true; |
| 41 | }; |
| 42 | |
| 43 | // Default integer traits disallow both 0 and -1 as keys (max value instead of -1 for unsigned). |
| 44 | template<typename T> struct GenericHashTraitsBasecxx . . $ QTWTF/GenericHashTraitsBase#<true, T> { |
| 45 | static const bool emptyValueIsZerocxx . . $ QTWTF/GenericHashTraitsBase#emptyValueIsZero. = true; |
| 46 | static const bool needsDestructioncxx . . $ QTWTF/GenericHashTraitsBase#needsDestruction. = false; |
| 47 | static void constructDeletedValuecxx . . $ QTWTF/GenericHashTraitsBase#constructDeletedValue(8e935d9c2e576e3a).(T& slot) { slot = static_cast<T>(-1); } |
| 48 | static bool isDeletedValuecxx . . $ QTWTF/GenericHashTraitsBase#isDeletedValue(ee44d93984fb03e9).(T value) { return value ==cxx . . $ QTWTF/`operator==`(8bba44cd2316e962). static_cast<T>(-1); } |
| 49 | }; |
| 50 | |
| 51 | template<typename T> struct GenericHashTraitscxx . . $ QTWTF/GenericHashTraits# : GenericHashTraitsBasecxx . . $ QTWTF/GenericHashTraitsBase#<IsIntegercxx . . $ QTWTF/IsInteger#<T>::value, T> { |
| 52 | typedef T TraitTypecxx . . $ QTWTF/GenericHashTraits#TraitType#; |
| 53 | static T emptyValuecxx . . $ QTWTF/GenericHashTraits#emptyValue(5f357b03ed472e5e).() { return T(); } |
| 54 | }; |
| 55 | |
| 56 | template<typename T> struct HashTraitscxx . . $ QTWTF/HashTraits# : GenericHashTraitscxx . . $ QTWTF/GenericHashTraits#<T> { }; |
| 57 | |
| 58 | template<typename T> struct FloatHashTraitscxx . . $ QTWTF/FloatHashTraits# : GenericHashTraitscxx . . $ QTWTF/GenericHashTraits#<T> { |
| 59 | static const bool needsDestructioncxx . . $ QTWTF/FloatHashTraits#needsDestruction. = false; |
| 60 | static T emptyValuecxx . . $ QTWTF/FloatHashTraits#emptyValue(5f357b03ed472e5e).() { return stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<T>::infinity(); } |
| 61 | static void constructDeletedValuecxx . . $ QTWTF/FloatHashTraits#constructDeletedValue(8e935d9c2e576e3a).(T& slot) { slot = -cxx . . $ operator-(9247d7e2a6536fa6).stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<T>::infinity(); } |
| 62 | static bool isDeletedValuecxx . . $ QTWTF/FloatHashTraits#isDeletedValue(ee44d93984fb03e9).(T value) { return value ==cxx . . $ QTWTF/`operator==`(8bba44cd2316e962). -cxx . . $ operator-(9247d7e2a6536fa6).stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<T>::infinity(); } |
| 63 | }; |
| 64 | |
| 65 | template<> struct HashTraitscxx . . $ QTWTF/HashTraits#<float> : FloatHashTraits<float> { }; |
| 66 | template<> struct HashTraitscxx . . $ QTWTF/HashTraits#<double> : FloatHashTraits<double> { }; |
| 67 | |
| 68 | // Default unsigned traits disallow both 0 and max as keys -- use these traits to allow zero and disallow max - 1. |
| 69 | template<typename T> struct UnsignedWithZeroKeyHashTraitscxx . . $ QTWTF/UnsignedWithZeroKeyHashTraits# : GenericHashTraitscxx . . $ QTWTF/GenericHashTraits#<T> { |
| 70 | static const bool emptyValueIsZerocxx . . $ QTWTF/UnsignedWithZeroKeyHashTraits#emptyValueIsZero. = false; |
| 71 | static const bool needsDestructioncxx . . $ QTWTF/UnsignedWithZeroKeyHashTraits#needsDestruction. = false; |
| 72 | static T emptyValuecxx . . $ QTWTF/UnsignedWithZeroKeyHashTraits#emptyValue(5f357b03ed472e5e).() { return stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<T>::max(); } |
| 73 | static void constructDeletedValuecxx . . $ QTWTF/UnsignedWithZeroKeyHashTraits#constructDeletedValue(8e935d9c2e576e3a).(T& slot) { slot = stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<T>::max() -cxx . . $ operator-(9247d7e2a6536fa6). 1; } |
| 74 | static bool isDeletedValuecxx . . $ QTWTF/UnsignedWithZeroKeyHashTraits#isDeletedValue(ee44d93984fb03e9).(T value) { return value ==cxx . . $ QTWTF/`operator==`(b1a6445b02f80637). stdcxx . . $ std/::numeric_limitscxx . . $ std/numeric_limits#<T>::max() -cxx . . $ operator-(9247d7e2a6536fa6). 1; } |
| 75 | }; |
| 76 | |
| 77 | template<typename P> struct HashTraitscxx . . $ QTWTF/HashTraits#<P*> : GenericHashTraitscxx . . $ QTWTF/GenericHashTraits#<P*> { |
| 78 | static const bool emptyValueIsZerocxx . . $ QTWTF/HashTraits#emptyValueIsZero. = true; |
| 79 | static const bool needsDestructioncxx . . $ QTWTF/HashTraits#needsDestruction. = false; |
| 80 | static void constructDeletedValuecxx . . $ QTWTF/HashTraits#constructDeletedValue(cf61340cf45ae89c).(P*& slot) { slot = reinterpret_cast<P*>(-1); } |
| 81 | static bool isDeletedValuecxx . . $ QTWTF/HashTraits#isDeletedValue(4a2ab88644057ef5).(P* value) { return value ==cxx . . $ QTWTF/`operator==`(69feba05d53a7241). reinterpret_cast<P*>(-1); } |
| 82 | }; |
| 83 | |
| 84 | template<typename P> struct HashTraitscxx . . $ QTWTF/HashTraits#<RefPtrcxx . . $ QTWTF/RefPtr#<P> > : GenericHashTraitscxx . . $ QTWTF/GenericHashTraits#<RefPtrcxx . . $ QTWTF/RefPtr#<P> > { |
| 85 | static const bool emptyValueIsZerocxx . . $ QTWTF/HashTraits#emptyValueIsZero. = true; |
| 86 | static void constructDeletedValuecxx . . $ QTWTF/HashTraits#constructDeletedValue(6d8a637c098905b8).(RefPtrcxx . . $ QTWTF/RefPtr#<P>& slot) { new (&slot) RefPtrcxx . . $ QTWTF/RefPtr#<P>(HashTableDeletedValuecxx . . $ QTWTF/HashTableDeletedValue.); } |
| 87 | static bool isDeletedValuecxx . . $ QTWTF/HashTraits#isDeletedValue(e078f80c2da54eff).(const RefPtrcxx . . $ QTWTF/RefPtr#<P>& value) { return value.isHashTableDeletedValuecxx . . $ QTWTF/RefPtr#isHashTableDeletedValue(50ce9a9e25b4a850).(); } |
| 88 | }; |
| 89 | |
| 90 | // special traits for pairs, helpful for their use in HashMap implementation |
| 91 | |
| 92 | template<typename FirstTraitsArg, typename SecondTraitsArg> |
| 93 | struct PairHashTraitscxx . . $ QTWTF/PairHashTraits# : GenericHashTraitscxx . . $ QTWTF/GenericHashTraits#<paircxx . . $ QTWTF/pair#<typename FirstTraitsArg::TraitType, typename SecondTraitsArg::TraitType> > { |
| 94 | typedef FirstTraitsArg FirstTraitscxx . . $ QTWTF/PairHashTraits#FirstTraits#; |
| 95 | typedef SecondTraitsArg SecondTraitscxx . . $ QTWTF/PairHashTraits#SecondTraits#; |
| 96 | typedef paircxx . . $ QTWTF/pair#<typename FirstTraitscxx . . $ QTWTF/PairHashTraits#FirstTraits#::TraitType, typename SecondTraitscxx . . $ QTWTF/PairHashTraits#SecondTraits#::TraitType> TraitTypecxx . . $ QTWTF/PairHashTraits#TraitType#; |
| 97 | |
| 98 | static const bool emptyValueIsZerocxx . . $ QTWTF/PairHashTraits#emptyValueIsZero. = FirstTraitscxx . . $ QTWTF/PairHashTraits#FirstTraits#::emptyValueIsZero && SecondTraitscxx . . $ QTWTF/PairHashTraits#SecondTraits#::emptyValueIsZero; |
| 99 | static TraitTypecxx . . $ QTWTF/PairHashTraits#TraitType# emptyValuecxx . . $ QTWTF/PairHashTraits#emptyValue(5754b32696a56868).() { return make_pair(FirstTraitscxx . . $ QTWTF/PairHashTraits#FirstTraits#::emptyValue(), SecondTraitscxx . . $ QTWTF/PairHashTraits#SecondTraits#::emptyValue()); } |
| 100 | |
| 101 | static const bool needsDestructioncxx . . $ QTWTF/PairHashTraits#needsDestruction. = FirstTraitscxx . . $ QTWTF/PairHashTraits#FirstTraits#::needsDestruction || SecondTraitscxx . . $ QTWTF/PairHashTraits#SecondTraits#::needsDestruction; |
| 102 | |
| 103 | static void constructDeletedValuecxx . . $ QTWTF/PairHashTraits#constructDeletedValue(6460d564c87c0490).(TraitTypecxx . . $ QTWTF/PairHashTraits#TraitType#& slot) { FirstTraitscxx . . $ QTWTF/PairHashTraits#FirstTraits#::constructDeletedValue(slot.firstcxx . . $ std/pair#first.); } |
| 104 | static bool isDeletedValuecxx . . $ QTWTF/PairHashTraits#isDeletedValue(c4b5bd487cc55267).(const TraitTypecxx . . $ QTWTF/PairHashTraits#TraitType#& value) { return FirstTraitscxx . . $ QTWTF/PairHashTraits#FirstTraits#::isDeletedValue(value.firstcxx . . $ std/pair#first.); } |
| 105 | }; |
| 106 | |
| 107 | template<typename First, typename Second> |
| 108 | struct HashTraitscxx . . $ QTWTF/HashTraits#<paircxx . . $ QTWTF/pair#<First, Second> > : public PairHashTraitscxx . . $ QTWTF/PairHashTraits#<HashTraitscxx . . $ QTWTF/HashTraits#<First>, HashTraitscxx . . $ QTWTF/HashTraits#<Second> > { }; |
| 109 | |
| 110 | } // namespace WTF |
| 111 | |
| 112 | using WTFcxx . . $ QTWTF/::HashTraitscxx . . $ QTWTF/HashTraits#; |
| 113 | using WTFcxx . . $ QTWTF/::PairHashTraitscxx . . $ PairHashTraits#; |
| 114 | |
| 115 | #endif // WTF_HashTraits_h |