Overte C++ Documentation
HashKey.h
1 //
2 // HashKey.h
3 // libraries/shared/src
4 //
5 // Created by Andrew Meadows 2017.10.25
6 // Copyright 2017 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_HashKey_h
13 #define hifi_HashKey_h
14 
15 #include <cstddef>
16 #include <stdint.h>
17 
18 #include <glm/glm.hpp>
19 
20 
21 // HashKey for use with btHashMap which requires a particular API for its keys. In particular it
22 // requires its Key to implement these methods:
23 //
24 // bool Key::equals()
25 // int32_t Key::getHash()
26 //
27 // The important thing about the HashKey implementation is that while getHash() returns 32-bits,
28 // internally HashKey stores a 64-bit hash which is used for the equals() comparison. This allows
29 // btHashMap to insert "dupe" 32-bit keys to different "values".
30 
31 class HashKey {
32 public:
33  class Hasher {
34  public:
35  Hasher() {}
36  void hashUint64(uint64_t data);
37  void hashFloat(float data);
38  void hashVec3(const glm::vec3& data);
39  uint64_t getHash64() const { return _hash; }
40  private:
41  uint64_t _hash { 0 };
42  uint8_t _hashCount { 0 };
43  };
44 
45  static float getNumQuantizedValuesPerMeter();
46 
47  HashKey() {}
48  HashKey(uint64_t hash) : _hash(hash) {}
49 
50  // These two methods are required by btHashMap.
51  bool equals(const HashKey& other) const { return _hash == other._hash; }
52  int32_t getHash() const { return (int32_t)((uint32_t)_hash); }
53 
54  uint64_t getHash64() const { return _hash; }
55 private:
56  uint64_t _hash { 0 };
57 };
58 
59 #endif // hifi_HashKey_h