MRPT  2.0.4
ts_hash_map.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "containers-precomp.h" // Precompiled headers
11 
13 #include <mrpt/core/byte_manip.h> // MAKEWORD16B(), etc.
14 #include <cstdlib>
15 #include <cstring>
16 
18  const std::string_view& value, uint64_t& out_hash)
19 {
20  // dbj2 method:
21  uint64_t hash = 5381;
22  for (auto c : value) hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
23  out_hash = hash;
24 }
26  const std::string_view& value, uint8_t& out_hash)
27 {
28  uint64_t hash;
29  reduced_hash(value, hash);
30  out_hash =
31  ((SELBYTE0(hash) ^ SELBYTE1(hash)) ^ SELBYTE2(hash)) ^ SELBYTE3(hash);
32 }
34  const std::string_view& value, uint16_t& out_hash)
35 {
36  uint64_t hash;
37  reduced_hash(value, hash);
38  out_hash = MAKEWORD16B(
39  SELBYTE0(hash) ^ SELBYTE1(hash), SELBYTE2(hash) ^ SELBYTE3(hash));
40 }
41 
43  const std::string_view& value, uint32_t& out_hash)
44 {
45  uint64_t hash;
46  reduced_hash(value, hash);
47  out_hash = (hash & 0xffffffff) ^ ((hash >> 32) & 0xffffffff);
48 }
void reduced_hash(const std::string_view &value, uint8_t &hash)
hash function used by ts_hash_map.
Definition: ts_hash_map.cpp:25
#define SELBYTE0(v)
Definition: byte_manip.h:11
#define SELBYTE1(v)
Definition: byte_manip.h:12
#define MAKEWORD16B(__LOBYTE, __HILOBYTE)
Definition: byte_manip.h:16
#define SELBYTE3(v)
Definition: byte_manip.h:14
#define SELBYTE2(v)
Definition: byte_manip.h:13



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020