mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:57:45 +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:
parent
5241c5f219
commit
368e74fdf8
1 changed files with 2 additions and 2 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue