Line data Source code
1 : //* This file is part of the MOOSE framework 2 : //* https://mooseframework.inl.gov 3 : //* 4 : //* All rights reserved, see COPYRIGHT for full restrictions 5 : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT 6 : //* 7 : //* Licensed under LGPL 2.1, please see LICENSE for details 8 : //* https://www.gnu.org/licenses/lgpl-2.1.html 9 : 10 : #pragma once 11 : 12 : #include <functional> 13 : #include <vector> 14 : #include <utility> 15 : #include <set> 16 : 17 : namespace Moose 18 : { 19 : 20 : /// Used for hash function specialization for Attribute objects. 21 : inline void 22 989634193 : hash_combine(std::size_t & /*seed*/) 23 : { 24 989634193 : } 25 : 26 : /// Used to combine an existing hash value with the hash of one or more other values (v and rest). 27 : /// For example "auto h = std::hash("hello"); hash_combine(h, my_int_val, my_float_val, etc.);" 28 : template <typename T, typename... Rest> 29 : inline void 30 1035073176 : hash_combine(std::size_t & seed, const T & v, Rest &&... rest) 31 : { 32 : std::hash<T> hasher; 33 1035073176 : seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2); 34 1035073176 : hash_combine(seed, std::forward<Rest>(rest)...); 35 1035073176 : } 36 : 37 : /// Used for hash function specialization for Attribute objects. 38 : template <typename T, typename... Rest> 39 : inline void 40 59544286 : hash_combine(std::size_t & seed, const std::vector<T> & v, Rest &&... rest) 41 : { 42 132477013 : for (auto & val : v) 43 72932727 : hash_combine(seed, val); 44 59544286 : hash_combine(seed, std::forward<Rest>(rest)...); 45 59544286 : } 46 : 47 : /// Used for hash function specialization for Attribute objects. 48 : template <typename T, typename... Rest> 49 : inline void 50 23958816 : hash_combine(std::size_t & seed, const std::set<T> & v, Rest &&... rest) 51 : { 52 47917632 : for (auto & val : v) 53 23958816 : hash_combine(seed, val); 54 23958816 : hash_combine(seed, std::forward<Rest>(rest)...); 55 23958816 : } 56 : } 57 : 58 : namespace std 59 : { 60 : 61 : template <typename S, typename T> 62 : struct hash<std::pair<S, T>> 63 : { 64 98260969 : inline size_t operator()(const std::pair<S, T> & val) const 65 : { 66 98260969 : size_t seed = 0; 67 98260969 : Moose::hash_combine(seed, val.first, val.second); 68 98260969 : return seed; 69 : } 70 : }; 71 : }