From 453434d0a99cf069777049230d135478dbfe848c Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Fri, 13 Apr 2018 09:26:54 +0200 Subject: [PATCH] [SMPI] Add code to support std::tuple for std::unordered_map This is currently in the replay file because it's only needed there. I hope that a better solution can be proposed (or we should move this to a header file). The reason for adding this code here is that it will be used in future commits (for identifying replay send/recv actions through triplets, (src,dst,tag)). This commit has been split from others to make the commits smaller. --- src/smpi/internals/smpi_replay.cpp | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/smpi/internals/smpi_replay.cpp b/src/smpi/internals/smpi_replay.cpp index de586295a7..7eb9815677 100644 --- a/src/smpi/internals/smpi_replay.cpp +++ b/src/smpi/internals/smpi_replay.cpp @@ -21,6 +21,60 @@ using simgrid::s4u::Actor; +#include +// From https://stackoverflow.com/questions/7110301/generic-hash-for-tuples-in-unordered-map-unordered-set +// This is all just to make std::unordered_map work with std::tuple. If we need this in other places, +// this could go into a header file. +namespace hash_tuple{ + template + struct hash + { + size_t + operator()(TT const& tt) const + { + return std::hash()(tt); + } + }; + + template + inline void hash_combine(std::size_t& seed, T const& v) + { + seed ^= hash_tuple::hash()(v) + 0x9e3779b9 + (seed<<6) + (seed>>2); + } + + // Recursive template code derived from Matthieu M. + template ::value - 1> + struct HashValueImpl + { + static void apply(size_t& seed, Tuple const& tuple) + { + HashValueImpl::apply(seed, tuple); + hash_combine(seed, std::get(tuple)); + } + }; + + template + struct HashValueImpl + { + static void apply(size_t& seed, Tuple const& tuple) + { + hash_combine(seed, std::get<0>(tuple)); + } + }; + + template + struct hash> + { + size_t + operator()(std::tuple const& tt) const + { + size_t seed = 0; + HashValueImpl >::apply(seed, tt); + return seed; + } + }; +} + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_replay,smpi,"Trace Replay with SMPI"); static std::unordered_map*> reqq; -- 2.20.1