OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2005, 2006, 2007, 2008, 2011, 2012 Apple Inc. All rights reserv
ed. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // for cases like String that need them. | 47 // for cases like String that need them. |
48 static const bool hasIsEmptyValueFunction = false; | 48 static const bool hasIsEmptyValueFunction = false; |
49 | 49 |
50 // The needsDestruction flag is used to optimize destruction and rehashi
ng. | 50 // The needsDestruction flag is used to optimize destruction and rehashi
ng. |
51 static const bool needsDestruction = true; | 51 static const bool needsDestruction = true; |
52 | 52 |
53 // The starting table size. Can be overridden when we know beforehand th
at | 53 // The starting table size. Can be overridden when we know beforehand th
at |
54 // a hash table will have at least N entries. | 54 // a hash table will have at least N entries. |
55 static const int minimumTableSize = 8; | 55 static const int minimumTableSize = 8; |
56 | 56 |
57 // By default, nothing needs to be done with the keys and values when | 57 static const bool needsTracing = NeedsTracing<T>::value; |
58 // visiting the hash table. | |
59 static const bool needsVisiting = NeedsVisiting<T>::value; | |
60 static const bool isWeak = IsWeak<T>::value; | 58 static const bool isWeak = IsWeak<T>::value; |
61 }; | 59 }; |
62 | 60 |
63 // Default integer traits disallow both 0 and -1 as keys (max value instead
of -1 for unsigned). | 61 // Default integer traits disallow both 0 and -1 as keys (max value instead
of -1 for unsigned). |
64 template<typename T> struct GenericHashTraitsBase<true, T> : GenericHashTrai
tsBase<false, T> { | 62 template<typename T> struct GenericHashTraitsBase<true, T> : GenericHashTrai
tsBase<false, T> { |
65 static const bool emptyValueIsZero = true; | 63 static const bool emptyValueIsZero = true; |
66 static const bool needsDestruction = false; | 64 static const bool needsDestruction = false; |
67 static void constructDeletedValue(T& slot) { slot = static_cast<T>(-1);
} | 65 static void constructDeletedValue(T& slot) { slot = static_cast<T>(-1);
} |
68 static bool isDeletedValue(T value) { return value == static_cast<T>(-1)
; } | 66 static bool isDeletedValue(T value) { return value == static_cast<T>(-1)
; } |
69 }; | 67 }; |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 struct KeyValuePairHashTraits : GenericHashTraits<KeyValuePair<typename KeyT
raitsArg::TraitType, typename ValueTraitsArg::TraitType> > { | 241 struct KeyValuePairHashTraits : GenericHashTraits<KeyValuePair<typename KeyT
raitsArg::TraitType, typename ValueTraitsArg::TraitType> > { |
244 typedef KeyTraitsArg KeyTraits; | 242 typedef KeyTraitsArg KeyTraits; |
245 typedef ValueTraitsArg ValueTraits; | 243 typedef ValueTraitsArg ValueTraits; |
246 typedef KeyValuePair<typename KeyTraits::TraitType, typename ValueTraits
::TraitType> TraitType; | 244 typedef KeyValuePair<typename KeyTraits::TraitType, typename ValueTraits
::TraitType> TraitType; |
247 typedef KeyValuePair<typename KeyTraits::EmptyValueType, typename ValueT
raits::EmptyValueType> EmptyValueType; | 245 typedef KeyValuePair<typename KeyTraits::EmptyValueType, typename ValueT
raits::EmptyValueType> EmptyValueType; |
248 | 246 |
249 static const bool emptyValueIsZero = KeyTraits::emptyValueIsZero && Valu
eTraits::emptyValueIsZero; | 247 static const bool emptyValueIsZero = KeyTraits::emptyValueIsZero && Valu
eTraits::emptyValueIsZero; |
250 static EmptyValueType emptyValue() { return KeyValuePair<typename KeyTra
its::EmptyValueType, typename ValueTraits::EmptyValueType>(KeyTraits::emptyValue
(), ValueTraits::emptyValue()); } | 248 static EmptyValueType emptyValue() { return KeyValuePair<typename KeyTra
its::EmptyValueType, typename ValueTraits::EmptyValueType>(KeyTraits::emptyValue
(), ValueTraits::emptyValue()); } |
251 | 249 |
252 static const bool needsDestruction = KeyTraits::needsDestruction || Valu
eTraits::needsDestruction; | 250 static const bool needsDestruction = KeyTraits::needsDestruction || Valu
eTraits::needsDestruction; |
253 static const bool needsVisiting = KeyTraits::needsVisiting || ValueTrait
s::needsVisiting; | 251 static const bool needsTracing = KeyTraits::needsTracing || ValueTraits:
:needsTracing; |
254 static const bool isWeak = KeyTraits::isWeak || ValueTraits::isWeak; | 252 static const bool isWeak = KeyTraits::isWeak || ValueTraits::isWeak; |
255 | 253 |
256 static const int minimumTableSize = KeyTraits::minimumTableSize; | 254 static const int minimumTableSize = KeyTraits::minimumTableSize; |
257 | 255 |
258 static void constructDeletedValue(TraitType& slot) { KeyTraits::construc
tDeletedValue(slot.key); } | 256 static void constructDeletedValue(TraitType& slot) { KeyTraits::construc
tDeletedValue(slot.key); } |
259 static bool isDeletedValue(const TraitType& value) { return KeyTraits::i
sDeletedValue(value.key); } | 257 static bool isDeletedValue(const TraitType& value) { return KeyTraits::i
sDeletedValue(value.key); } |
260 }; | 258 }; |
261 | 259 |
262 template<typename Key, typename Value> | 260 template<typename Key, typename Value> |
263 struct HashTraits<KeyValuePair<Key, Value> > : public KeyValuePairHashTraits
<HashTraits<Key>, HashTraits<Value> > { }; | 261 struct HashTraits<KeyValuePair<Key, Value> > : public KeyValuePairHashTraits
<HashTraits<Key>, HashTraits<Value> > { }; |
264 | 262 |
265 template<typename T> | 263 template<typename T> |
266 struct NullableHashTraits : public HashTraits<T> { | 264 struct NullableHashTraits : public HashTraits<T> { |
267 static const bool emptyValueIsZero = false; | 265 static const bool emptyValueIsZero = false; |
268 static T emptyValue() { return reinterpret_cast<T>(1); } | 266 static T emptyValue() { return reinterpret_cast<T>(1); } |
269 }; | 267 }; |
270 | 268 |
271 } // namespace WTF | 269 } // namespace WTF |
272 | 270 |
273 using WTF::HashTraits; | 271 using WTF::HashTraits; |
274 using WTF::PairHashTraits; | 272 using WTF::PairHashTraits; |
275 using WTF::NullableHashTraits; | 273 using WTF::NullableHashTraits; |
276 using WTF::SimpleClassHashTraits; | 274 using WTF::SimpleClassHashTraits; |
277 | 275 |
278 #endif // WTF_HashTraits_h | 276 #endif // WTF_HashTraits_h |
OLD | NEW |