1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:37:44 +00:00

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).
This commit is contained in:
Leandro Pereira 2021-09-30 21:33:55 -07:00 committed by Andreas Kling
parent 5241c5f219
commit 368e74fdf8

View file

@ -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);