LCOV - code coverage report
Current view: top level - DCPS - Hash.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 11 11 100.0 %
Date: 2023-04-30 01:32:43 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Distributed under the OpenDDS License.
       3             :  * See: http://www.opendds.org/license.html
       4             :  */
       5             : 
       6             : #ifndef OPENDDS_DCPS_HASH_H
       7             : #define OPENDDS_DCPS_HASH_H
       8             : 
       9             : #include "dds/Versioned_Namespace.h"
      10             : 
      11             : #include "dcps_export.h"
      12             : 
      13             : #ifdef ACE_HAS_CPP11
      14             : #include <cstdint>
      15             : #endif
      16             : 
      17             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      18             : namespace OpenDDS {
      19             : namespace DCPS {
      20             : 
      21             : typedef unsigned char MD5Result[16];
      22             : 
      23             : OpenDDS_Dcps_Export
      24             : void MD5Hash(MD5Result& result, const void* input, size_t size);
      25             : 
      26             : #ifdef ACE_HAS_CPP11
      27             : OpenDDS_Dcps_Export
      28        2268 : inline uint32_t one_at_a_time_hash(const uint8_t* key, size_t length, uint32_t start_hash = 0u)
      29             : {
      30        2268 :   uint32_t hash = start_hash;
      31        2268 :   size_t i = 0;
      32     3714308 :   while (i != length) {
      33     3712040 :     hash += key[i++];
      34     3712040 :     hash += hash << 10;
      35     3712040 :     hash ^= hash >> 6;
      36             :   }
      37        2268 :   hash += hash << 3;
      38        2268 :   hash ^= hash >> 11;
      39        2268 :   hash += hash << 15;
      40        2268 :   return hash;
      41             : }
      42             : #endif
      43             : 
      44             : }
      45             : }
      46             : OPENDDS_END_VERSIONED_NAMESPACE_DECL
      47             : 
      48             : #ifdef ACE_HAS_CPP11
      49             : #define OPENDDS_OOAT_STD_HASH(Key, Export) \
      50             :   namespace std \
      51             :   { \
      52             :   template<> struct Export hash<Key> \
      53             :   { \
      54             :     std::size_t operator()(const Key& val) const noexcept \
      55             :     { \
      56             :       return static_cast<size_t>(OpenDDS::DCPS::one_at_a_time_hash(reinterpret_cast<const uint8_t*>(&val), sizeof (Key))); \
      57             :     } \
      58             :   }; \
      59             :   }
      60             : #endif
      61             : 
      62             : #ifdef ACE_HAS_CPP11
      63             : #define OPENDDS_OOAT_CUSTOM_HASH(Key, Export, Name) \
      64             :   struct Export Name \
      65             :   { \
      66             :     std::size_t operator()(const Key& val) const noexcept \
      67             :     { \
      68             :       return static_cast<size_t>(OpenDDS::DCPS::one_at_a_time_hash(reinterpret_cast<const uint8_t*>(&val), sizeof (Key))); \
      69             :     } \
      70             :   };
      71             : #endif
      72             : 
      73             : #endif // OPENDDS_DCPS_HASH_H

Generated by: LCOV version 1.16