Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_HASH_UTIL_H_ | |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_HASH_UTIL_H_ | |
| 7 | |
| 8 #include <type_traits> | |
| 9 | |
| 10 #include "mojo/public/cpp/bindings/lib/hash_util.h" | |
| 11 #include "mojo/public/cpp/bindings/struct_ptr.h" | |
| 12 #include "third_party/WebKit/Source/wtf/HashFunctions.h" | |
| 13 #include "third_party/WebKit/Source/wtf/HashMap.h" | |
| 14 #include "third_party/WebKit/Source/wtf/Optional.h" | |
|
yzshen1
2016/09/21 23:17:52
Some of the includes are not needed, please remove
tibell
2016/09/22 05:17:23
Done.
| |
| 15 #include "third_party/WebKit/Source/wtf/Vector.h" | |
| 16 #include "third_party/WebKit/Source/wtf/text/StringHash.h" | |
| 17 #include "third_party/WebKit/Source/wtf/text/WTFString.h" | |
| 18 | |
| 19 namespace mojo { | |
| 20 namespace internal { | |
| 21 | |
| 22 template <> | |
| 23 struct HashTraits<WTF::String, false> { | |
| 24 static size_t Hash(size_t seed, const WTF::String& value) { | |
| 25 return HashCombine(seed, WTF::StringHash::hash(value)); | |
| 26 } | |
| 27 }; | |
| 28 | |
| 29 template <typename T> | |
| 30 struct StructPtrHashFn { | |
| 31 static unsigned hash(const StructPtr<T>& value) { | |
| 32 return value.Hash(kHashSeed); | |
| 33 } | |
| 34 static bool equal(const StructPtr<T>& left, const StructPtr<T>& right) { | |
| 35 return left.Equals(right); | |
| 36 } | |
| 37 static const bool safeToCompareToEmptyOrDeleted = false; | |
| 38 }; | |
| 39 | |
| 40 template <typename T> | |
| 41 struct InlinedStructPtrHashFn { | |
| 42 static unsigned hash(const InlinedStructPtr<T>& value) { | |
| 43 return value.Hash(kHashSeed); | |
| 44 } | |
| 45 static bool equal(const InlinedStructPtr<T>& left, | |
| 46 const InlinedStructPtr<T>& right) { | |
| 47 return left.Equals(right); | |
| 48 } | |
| 49 static const bool safeToCompareToEmptyOrDeleted = false; | |
| 50 }; | |
| 51 | |
| 52 } // namespace internal | |
| 53 } // namespace mojo | |
| 54 | |
| 55 namespace WTF { | |
| 56 | |
| 57 template <typename T> | |
| 58 struct DefaultHash<mojo::StructPtr<T>> { | |
| 59 using Hash = mojo::internal::StructPtrHashFn<T>; | |
| 60 }; | |
| 61 | |
| 62 template <typename T> | |
| 63 struct HashTraits<mojo::StructPtr<T>> | |
| 64 : public GenericHashTraits<mojo::StructPtr<T>> { | |
| 65 static const bool hasIsEmptyValueFunction = true; | |
| 66 static bool isEmptyValue(const mojo::StructPtr<T>& value) { | |
| 67 return value.is_null(); | |
| 68 } | |
| 69 static void constructDeletedValue(mojo::StructPtr<T>& slot, bool) { | |
| 70 mojo::StructPtr<T>::constructDeletedValue(slot); | |
| 71 } | |
| 72 static bool isDeletedValue(const mojo::StructPtr<T>& value) { | |
| 73 return value.isHashTableDeletedValue(); | |
| 74 } | |
| 75 }; | |
| 76 | |
| 77 template <typename T> | |
| 78 struct DefaultHash<mojo::InlinedStructPtr<T>> { | |
| 79 using Hash = mojo::internal::InlinedStructPtrHashFn<T>; | |
| 80 }; | |
| 81 | |
| 82 template <typename T> | |
| 83 struct HashTraits<mojo::InlinedStructPtr<T>> | |
| 84 : public GenericHashTraits<mojo::InlinedStructPtr<T>> { | |
| 85 static const bool hasIsEmptyValueFunction = true; | |
| 86 static bool isEmptyValue(const mojo::InlinedStructPtr<T>& value) { | |
| 87 return value.is_null(); | |
| 88 } | |
| 89 static void constructDeletedValue(mojo::InlinedStructPtr<T>& slot, bool) { | |
| 90 mojo::InlinedStructPtr<T>::constructDeletedValue(slot); | |
| 91 } | |
| 92 static bool isDeletedValue(const mojo::InlinedStructPtr<T>& value) { | |
| 93 return value.isHashTableDeletedValue(); | |
| 94 } | |
| 95 }; | |
| 96 | |
| 97 } // namespace WTF | |
| 98 | |
| 99 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_WTF_HASH_UTIL_H_ | |
| OLD | NEW |