Skip to content

Commit

Permalink
Updating std::hast<EntityId_t> to get a better unordered containers d…
Browse files Browse the repository at this point in the history
…istribution (#868)

* Updating std::hast<EntityId_t> to recover the actual participant entity counter.

* Aplying review comments
  • Loading branch information
MiguelBarro authored Feb 11, 2020
1 parent 8e47167 commit 4134783
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions include/fastrtps/rtps/common/EntityId_t.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,21 @@ struct hash<eprosima::fastrtps::rtps::EntityId_t>
std::size_t operator()(
const eprosima::fastrtps::rtps::EntityId_t& k) const
{
const uint32_t* aux = reinterpret_cast<const uint32_t*>(k.value);
return static_cast<std::size_t>(*aux);
// recover the participant entity counter
eprosima::fastrtps::rtps::octet value[4];

#if __BIG_ENDIAN__
value[3] = k.value[2];
value[2] = k.value[1];
value[1] = k.value[0];
value[0] = 0;
#else
value[3] = 0;
value[2] = k.value[0];
value[1] = k.value[1];
value[0] = k.value[2];
#endif
return static_cast<std::size_t>(*reinterpret_cast<const uint32_t*>(&value));
}
};

Expand Down

0 comments on commit 4134783

Please sign in to comment.