mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-30 06:06:48 +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
Notes:
sideshowbarker
2024-07-18 01:52:57 +09:00
Author: https://github.com/lpereira
Commit: 368e74fdf8
Pull-request: https://github.com/SerenityOS/serenity/pull/10278
Reviewed-by: https://github.com/kleinesfilmroellchen ✅
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