Victor Boivie | 553fd32 | 2021-04-26 15:25:06 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | #ifndef RTC_BASE_HASH_H_ |
| 11 | #define RTC_BASE_HASH_H_ |
| 12 | |
| 13 | #include <stddef.h> |
| 14 | |
| 15 | #include <functional> |
| 16 | #include <utility> |
| 17 | |
| 18 | namespace webrtc { |
| 19 | |
| 20 | // A custom hash function for std::pair, to be able to be used as key in a |
| 21 | // std::unordered_map. If absl::flat_hash_map would ever be used, this is |
| 22 | // unnecessary as it already has a hash function for std::pair. |
| 23 | struct PairHash { |
| 24 | template <class T1, class T2> |
| 25 | size_t operator()(const std::pair<T1, T2>& p) const { |
| 26 | return (3 * std::hash<T1>{}(p.first)) ^ std::hash<T2>{}(p.second); |
| 27 | } |
| 28 | }; |
| 29 | |
| 30 | } // namespace webrtc |
| 31 | |
| 32 | #endif // RTC_BASE_HASH_H_ |