Line data Source code
1 : // The libMesh Finite Element Library. 2 : // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 3 : 4 : // This library is free software; you can redistribute it and/or 5 : // modify it under the terms of the GNU Lesser General Public 6 : // License as published by the Free Software Foundation; either 7 : // version 2.1 of the License, or (at your option) any later version. 8 : 9 : // This library is distributed in the hope that it will be useful, 10 : // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 : // Lesser General Public License for more details. 13 : 14 : // You should have received a copy of the GNU Lesser General Public 15 : // License along with this library; if not, write to the Free Software 16 : // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 : 18 : #ifndef LIBMESH_HASHING_H 19 : #define LIBMESH_HASHING_H 20 : 21 : #include <functional> 22 : 23 : namespace libMesh 24 : { 25 : namespace boostcopy 26 : { 27 : 28 12107909 : inline void hash_combine_impl(std::size_t & seed, std::size_t value) 29 : { 30 116449068 : seed ^= value + 0x9e3779b9 + (seed<<6) + (seed>>2); 31 12107909 : } 32 : 33 : template <typename T> 34 12107907 : inline void hash_combine(std::size_t & seed, const T & value) 35 : { 36 : using std::hash; 37 113619484 : hash_combine_impl(seed, hash<T>{}(value)); 38 12107907 : } 39 : 40 : } 41 : 42 : 43 : // Fix for STL laziness 44 : struct hash { 45 : public: 46 : template <typename T1, typename T2> 47 11971590 : std::size_t operator()(const std::pair<T1, T2> & x) const 48 : { 49 : // Hopefully argument-based lookup lets us recurse with this 50 : using std::hash; 51 : 52 120262080 : std::size_t returnval = hash<T1>()(x.first); 53 18838559 : boostcopy::hash_combine(returnval, x.second); 54 : 55 11971590 : return returnval; 56 : } 57 : 58 : template <typename T, std::size_t N> 59 32260 : std::size_t operator()(const std::array<T, N> & x) const 60 : { 61 : // Hopefully argument-based lookup lets us recurse with this 62 : using std::hash; 63 : 64 2908 : std::size_t returnval = 0; 65 140672 : for (std::size_t i = 0; i != N; ++i) 66 17448 : boostcopy::hash_combine(returnval, x[i]); 67 : 68 32260 : return returnval; 69 : } 70 : }; 71 : 72 : 73 : } 74 : 75 : #endif // LIBMESH_HASHING_H