MRPT  2.0.1
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.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020