1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 18:27:39 +00:00

AK: Make StringView::hash() constexpr

This required moving string_hash() to its own header so that everyone
can see it.
This commit is contained in:
Andreas Kling 2021-05-14 15:21:50 +02:00
parent 9c38475608
commit 3e603b2f32
5 changed files with 36 additions and 25 deletions

27
AK/StringHash.h Normal file
View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2018-2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
namespace AK {
constexpr u32 string_hash(char const* characters, size_t length)
{
u32 hash = 0;
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;