From 079e167e7c62c857e271bda0588064dc4030e337 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 20 Apr 2016 14:19:07 +0200 Subject: Add combine_hash() utility --- butl/utility | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/butl/utility b/butl/utility index 1cc45ef..efbb13b 100644 --- a/butl/utility +++ b/butl/utility @@ -5,6 +5,7 @@ #ifndef BUTL_UTILITY #define BUTL_UTILITY +#include // std::size_t #include // forward() #include // strcmp @@ -26,6 +27,23 @@ namespace butl bool operator() (const P& x, const P& y) const {return *x < *y;} }; + // Combine one or more hash values. + // + inline std::size_t + combine_hash (std::size_t s, std::size_t h) + { + // Magic formula from boost::hash_combine(). + // + return s ^ (h + 0x9e3779b9 + (s << 6) + (s >> 2)); + } + + template + inline std::size_t + combine_hash (std::size_t s, std::size_t h, S... hs) + { + return combine_hash (combine_hash (s, h), hs...); + } + // Support for reverse iteration using range-based for-loop: // // for (... : reverse_iterate (x)) ... -- cgit v1.1