Line | Branch | Exec | Source |
---|---|---|---|
1 | // This file is part of INSTINCT, the INS Toolkit for Integrated | ||
2 | // Navigation Concepts and Training by the Institute of Navigation of | ||
3 | // the University of Stuttgart, Germany. | ||
4 | // | ||
5 | // This Source Code Form is subject to the terms of the Mozilla Public | ||
6 | // License, v. 2.0. If a copy of the MPL was not distributed with this | ||
7 | // file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
8 | |||
9 | /// @file Pair.hpp | ||
10 | /// @brief Utility functions for std::pair | ||
11 | /// @author T. Topp (topp@ins.uni-stuttgart.de) | ||
12 | /// @date 2022-12-19 | ||
13 | |||
14 | #pragma once | ||
15 | |||
16 | #include <cstddef> | ||
17 | #include <utility> | ||
18 | #include <functional> | ||
19 | |||
20 | namespace std | ||
21 | { | ||
22 | /// @brief A hash function used to hash a pair of any kind (needed for unordered_map) | ||
23 | template<class T1, class T2> | ||
24 | struct hash<std::pair<T1, T2>> | ||
25 | { | ||
26 | /// @brief Hash function for std::pair | ||
27 | /// @param[in] f Pair | ||
28 | 13221 | std::size_t operator()(const std::pair<T1, T2>& f) const | |
29 | { | ||
30 | 13221 | auto hash1 = std::hash<T1>{}(f.first); | |
31 | 13221 | auto hash2 = std::hash<T2>{}(f.second); | |
32 | |||
33 |
1/2✓ Branch 0 taken 13221 times.
✗ Branch 1 not taken.
|
13221 | if (hash1 != hash2) |
34 | { | ||
35 | 13221 | return hash1 ^ hash2 << 1; | |
36 | } | ||
37 | |||
38 | // If hash1 == hash2, their XOR is zero. | ||
39 | ✗ | return hash1; | |
40 | } | ||
41 | }; | ||
42 | } // namespace std | ||
43 |