Changeset 11739 in webkit for trunk/JavaScriptCore/kxmlcore/HashTraits.h
- Timestamp:
- Dec 22, 2005, 5:52:43 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kxmlcore/HashTraits.h
r11719 r11739 24 24 #define KXMLCORE_HASH_TRAITS_H 25 25 26 #include "RefPtr.h" 26 27 #include <utility> 27 28 … … 45 46 46 47 template<typename T> 47 struct HashTraits {48 typedef T traitType;48 struct GenericHashTraits { 49 typedef T TraitType; 49 50 static const bool emptyValueIsZero = IsInteger<T>::value; 50 51 static traitType emptyValue() { 52 return traitType(); 53 } 51 static const bool needsDestruction = !IsInteger<T>::value; 52 static TraitType emptyValue() { return IsInteger<T>::value ? 0 : TraitType(); } 53 }; 54 55 template<typename T> 56 struct HashTraits : GenericHashTraits<T> { 54 57 }; 55 58 56 59 // may not be appropriate for all uses since it would disallow 0 and -1 as keys 57 60 template<> 58 struct HashTraits<int> { 59 typedef int traitType; 61 struct HashTraits<int> : GenericHashTraits<int> { 62 static TraitType deletedValue() { return -1; } 63 }; 64 65 template<typename P> 66 struct HashTraits<P *> : GenericHashTraits<P *> { 67 typedef P *TraitType; 60 68 static const bool emptyValueIsZero = true; 69 static const bool needsDestruction = false; 70 static TraitType emptyValue() { return reinterpret_cast<P *>(0); } 71 static TraitType deletedValue() { return reinterpret_cast<P *>(-1); } 72 }; 73 74 template<typename P> 75 struct HashTraits<RefPtr<P> > : GenericHashTraits<RefPtr<P> > { 76 static const bool emptyValueIsZero = true; 77 }; 78 79 template<typename T, typename Traits> 80 class DeletedValueAssigner; 81 82 template<typename T, typename Traits> 83 inline void assignDeleted(T& location) 84 { 85 DeletedValueAssigner<T, Traits>::assignDeletedValue(location); 86 } 87 88 template<typename FirstTraits, typename SecondTraits> 89 struct PairHashTraits : GenericHashTraits<pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType> > { 90 private: 91 typedef typename FirstTraits::TraitType FirstType; 92 typedef typename SecondTraits::TraitType SecondType; 93 public: 94 typedef pair<FirstType, SecondType> TraitType; 95 96 static const bool emptyValueIsZero = FirstTraits::emptyValueIsZero && SecondTraits::emptyValueIsZero; 97 static const bool needsDestruction = FirstTraits::needsDestruction || SecondTraits::needsDestruction; 61 98 62 static traitType emptyValue() { 63 return 0; 99 static TraitType emptyValue() 100 { 101 return TraitType(FirstTraits::emptyValue(), SecondTraits::emptyValue()); 64 102 } 65 static traitType deletedValue() { 66 return -1; 103 104 static TraitType deletedValue() 105 { 106 return TraitType(FirstTraits::deletedValue(), SecondTraits::emptyValue()); 107 } 108 109 static void assignDeletedValue(TraitType& location) 110 { 111 assignDeleted<FirstType, FirstTraits>(location.first); 112 location.second = SecondTraits::emptyValue(); 67 113 } 68 114 }; 69 115 70 template<typename P>71 struct HashTraits< P *> {72 typedef P *traitType;73 static const bool emptyValueIsZero = true; 74 75 static traitType emptyValue() {76 return reinterpret_cast<P *>(0);77 }78 static traitType deletedValue() {79 return reinterpret_cast<P *>(-1);116 template<typename First, typename Second> 117 struct HashTraits<pair<First, Second> > : public PairHashTraits<HashTraits<First>, HashTraits<Second> > { 118 }; 119 120 template<typename T, typename Traits> 121 struct DeletedValueAssigner 122 { 123 static void assignDeletedValue(T& location) 124 { 125 location = Traits::deletedValue(); 80 126 } 81 127 }; 82 128 83 129 template<typename FirstTraits, typename SecondTraits> 84 struct PairHashTraits { 85 private: 86 typedef typename FirstTraits::traitType FirstType; 87 typedef typename SecondTraits::traitType SecondType; 88 public: 89 typedef pair<FirstType, SecondType> traitType; 90 91 static const bool emptyValueIsZero = FirstTraits::emptyValueIsZero && SecondTraits::emptyValueIsZero; 92 93 static traitType emptyValue() { 94 return traitType(FirstTraits::emptyValue(), SecondTraits::emptyValue()); 95 } 96 static traitType deletedValue() { 97 return traitType(FirstTraits::deletedValue(), SecondTraits::emptyValue()); 130 struct DeletedValueAssigner<pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType>, PairHashTraits<FirstTraits, SecondTraits> > 131 { 132 static void assignDeletedValue(pair<typename FirstTraits::TraitType, typename SecondTraits::TraitType>& location) 133 { 134 PairHashTraits<FirstTraits, SecondTraits>::assignDeletedValue(location); 98 135 } 99 136 }; 100 137 101 138 template<typename First, typename Second> 102 struct HashTraits<pair<First, Second> > : public PairHashTraits<HashTraits<First>, HashTraits<Second> > { 139 struct DeletedValueAssigner<pair<First, Second>, HashTraits<pair<First, Second> > > 140 { 141 static void assignDeletedValue(pair<First, Second>& location) 142 { 143 HashTraits<pair<First, Second> >::assignDeletedValue(location); 144 } 103 145 }; 146 104 147 105 148 } // namespace KXMLCore
Note:
See TracChangeset
for help on using the changeset viewer.