LCOV - code coverage report
Current view: top level - include/utils - MooseHashing.h (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 20 20 100.0 %
Date: 2025-07-17 01:28:37 Functions: 31 31 100.0 %
Legend: Lines: hit not hit

          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   883517241 : hash_combine(std::size_t & /*seed*/)
      23             : {
      24   883517241 : }
      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   924810409 : hash_combine(std::size_t & seed, const T & v, Rest &&... rest)
      31             : {
      32             :   std::hash<T> hasher;
      33   924810409 :   seed ^= hasher(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
      34   924810409 :   hash_combine(seed, std::forward<Rest>(rest)...);
      35   924810409 : }
      36             : 
      37             : /// Used for hash function specialization for Attribute objects.
      38             : template <typename T, typename... Rest>
      39             : inline void
      40    53381647 : hash_combine(std::size_t & seed, const std::vector<T> & v, Rest &&... rest)
      41             : {
      42   118875714 :   for (auto & val : v)
      43    65494067 :     hash_combine(seed, val);
      44    53381647 :   hash_combine(seed, std::forward<Rest>(rest)...);
      45    53381647 : }
      46             : 
      47             : /// Used for hash function specialization for Attribute objects.
      48             : template <typename T, typename... Rest>
      49             : inline void
      50    21292111 : hash_combine(std::size_t & seed, const std::set<T> & v, Rest &&... rest)
      51             : {
      52    42584222 :   for (auto & val : v)
      53    21292111 :     hash_combine(seed, val);
      54    21292111 :   hash_combine(seed, std::forward<Rest>(rest)...);
      55    21292111 : }
      56             : }
      57             : 
      58             : namespace std
      59             : {
      60             : 
      61             : template <typename S, typename T>
      62             : struct hash<std::pair<S, T>>
      63             : {
      64    88692026 :   inline size_t operator()(const std::pair<S, T> & val) const
      65             :   {
      66    88692026 :     size_t seed = 0;
      67    88692026 :     Moose::hash_combine(seed, val.first, val.second);
      68    88692026 :     return seed;
      69             :   }
      70             : };
      71             : }

Generated by: LCOV version 1.14