Forráskód Böngészése

AK: Allow seed value to be specified in string_hash()

For some algorithms, such as bloom filters, it's possible to reuse a
hash function (rather than having different hashing functions) if the
seed is different each time the hash function is used.

Modify AK::string_hash() to take a seed parameter, which defaults to 0
(the value the hash value was originally initialized to).
Leandro Pereira 3 éve
szülő
commit
368e74fdf8
1 módosított fájl, 2 hozzáadás és 2 törlés
  1. 2 2
      AK/StringHash.h

+ 2 - 2
AK/StringHash.h

@@ -10,9 +10,9 @@
 
 namespace AK {
 
-constexpr u32 string_hash(char const* characters, size_t length)
+constexpr u32 string_hash(char const* characters, size_t length, u32 seed = 0)
 {
-    u32 hash = 0;
+    u32 hash = seed;
     for (size_t i = 0; i < length; ++i) {
         hash += (u32)characters[i];
         hash += (hash << 10);