Blame view

3rdparty/boost_1_81_0/boost/multiprecision/detail/hash.hpp 1.38 KB
63e88f80   Hu Chunming   提交三方库
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
  ///////////////////////////////////////////////////////////////////////////////
  //  Copyright 2021 Matt Borland. Distributed under the Boost
  //  Software License, Version 1.0. (See accompanying file
  //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  
  #ifndef BOOST_MP_DETAIL_HASH_HPP
  #define BOOST_MP_DETAIL_HASH_HPP
  
  #include <cstddef>
  #include <functional>
  #include <boost/multiprecision/detail/standalone_config.hpp>
  
  namespace boost { namespace multiprecision { namespace detail {
  
  template <typename T>
  inline std::size_t hash_value(const T& v)
  {
      std::hash<T> hasher;
      return hasher(v);
  }
  
  #if defined(BOOST_HAS_INT128)
  
  std::size_t hash_value(const uint128_type& val);
  
  inline std::size_t hash_value(const int128_type& val)
  {
     return hash_value(static_cast<uint128_type>(val));
  }
  
  #endif
  
  inline void hash_combine(std::size_t&) {}
  
  template <typename T, typename... Args>
  inline void hash_combine(std::size_t& seed, const T& v, Args... args) 
  {
      constexpr std::size_t adder = 0x9e3779b9;
      seed = seed ^ (hash_value(v) + adder + (seed<<6) + (seed>>2));
      hash_combine(seed, args...);
  }
  
  #if defined(BOOST_HAS_INT128)
  
  inline std::size_t hash_value(const uint128_type& val)
  {
     std::size_t result = static_cast<std::size_t>(val);
     hash_combine(result, static_cast<std::size_t>(val >> 64));
     return result;
  }
  
  #endif
  
  }}} // Namespaces
  
  #endif // BOOST_MP_DETAIL_HASH_HPP