Browse Source

minor hash improvements

Kajetan Johannes Hammerle 1 year ago
parent
commit
dc74cb9221
2 changed files with 5 additions and 1 deletions
  1. 4 0
      data/HashMap.h
  2. 1 1
      utils/StringBuffer.h

+ 4 - 0
data/HashMap.h

@@ -247,10 +247,14 @@ private:
     }
 
     Hash fullHash(int key) const {
+        static_assert(sizeof(key) == sizeof(Hash),
+                      "unwanted loose of precision in hash");
         return key;
     }
 
     Hash fullHash(unsigned int key) const {
+        static_assert(sizeof(key) == sizeof(Hash),
+                      "unwanted loose of precision in hash");
         return key;
     }
 

+ 1 - 1
utils/StringBuffer.h

@@ -17,7 +17,7 @@ class StringBuffer final {
     char data[N];
 
     void addToHash(char c) {
-        hash = 2120251889 * hash + c;
+        hash = static_cast<Hash>(2120251889) * hash + static_cast<Hash>(c);
     }
 
     void addToHash(int from, int to) {