From 368e74fdf84e66ecd201a4eac5bb213022c486b3 Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Thu, 30 Sep 2021 21:33:55 -0700 Subject: [PATCH] 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). --- AK/StringHash.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AK/StringHash.h b/AK/StringHash.h index 1e28c8426d..1a166ae040 100644 --- a/AK/StringHash.h +++ b/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);