2021-05-14 13:21:50 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2021, the SerenityOS developers.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2021-09-15 22:00:33 +00:00
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2021-05-14 13:21:50 +00:00
|
|
|
namespace AK {
|
|
|
|
|
2021-10-01 04:33:55 +00:00
|
|
|
constexpr u32 string_hash(char const* characters, size_t length, u32 seed = 0)
|
2021-05-14 13:21:50 +00:00
|
|
|
{
|
2021-10-01 04:33:55 +00:00
|
|
|
u32 hash = seed;
|
2021-05-14 13:21:50 +00:00
|
|
|
for (size_t i = 0; i < length; ++i) {
|
|
|
|
hash += (u32)characters[i];
|
|
|
|
hash += (hash << 10);
|
|
|
|
hash ^= (hash >> 6);
|
|
|
|
}
|
|
|
|
hash += hash << 3;
|
|
|
|
hash ^= hash >> 11;
|
|
|
|
hash += hash << 15;
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::string_hash;
|