OpenDDS  Snapshot(2023/04/28-20:55)
Hash.h
Go to the documentation of this file.
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 
10 
11 #include "dcps_export.h"
12 
13 #ifdef ACE_HAS_CPP11
14 #include <cstdint>
15 #endif
16 
18 namespace OpenDDS {
19 namespace DCPS {
20 
21 typedef unsigned char MD5Result[16];
22 
24 void MD5Hash(MD5Result& result, const void* input, size_t size);
25 
26 #ifdef ACE_HAS_CPP11
28 inline uint32_t one_at_a_time_hash(const uint8_t* key, size_t length, uint32_t start_hash = 0u)
29 {
30  uint32_t hash = start_hash;
31  size_t i = 0;
32  while (i != length) {
33  hash += key[i++];
34  hash += hash << 10;
35  hash ^= hash >> 6;
36  }
37  hash += hash << 3;
38  hash ^= hash >> 11;
39  hash += hash << 15;
40  return hash;
41 }
42 #endif
43 
44 }
45 }
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
int hash(const std::vector< const DDS::OctetSeq *> &src, DDS::OctetSeq &dst)
void MD5Hash(MD5Result &result, const void *input, size_t size)
Definition: Hash.cpp:323
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
sequence< octet > key
unsigned char MD5Result[16]
Definition: Hash.h:21
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28