| 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 | 632914 | std::size_t operator()(const std::pair<T1, T2>& f) const | |
| 29 | { | ||
| 30 |
1/2✓ Branch 1 taken 618312 times.
✗ Branch 2 not taken.
|
632914 | auto hash1 = std::hash<T1>{}(f.first); |
| 31 | 632914 | auto hash2 = std::hash<T2>{}(f.second); | |
| 32 | |||
| 33 |
2/2✓ Branch 0 taken 597894 times.
✓ Branch 1 taken 35020 times.
|
632914 | if (hash1 != hash2) |
| 34 | { | ||
| 35 | 597894 | return hash1 ^ hash2 << 1; | |
| 36 | } | ||
| 37 | |||
| 38 | // If hash1 == hash2, their XOR is zero. | ||
| 39 | 35020 | return hash1; | |
| 40 | } | ||
| 41 | }; | ||
| 42 | } // namespace std | ||
| 43 |