MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_hash_fnv1a.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_HASH_FNV1A_H_1607309087
12#define INCGUARD_MGL_HASH_FNV1A_H_1607309087
13
14#include <cstdint>
15
16namespace MGL::Hash
17{
19constexpr uint32_t kFNV1aDefaultValue32 = 0xA3F6C23E;
21constexpr uint32_t kFNV1aPrime32 = 0x1000193;
23constexpr uint64_t kFNV1aDefaultValue64 = 0xC18F36FE9A341BC5;
25constexpr uint64_t kFNV1aPrime64 = 0x100000001B3;
26
27
28/* ------------------------------------------------------------------------- */
35/* ------------------------------------------------------------------------- */
36constexpr uint32_t FNV1a(const char *str, const uint32_t value = Hash::kFNV1aDefaultValue32) noexcept
37{
38 if (str[0] == '\0')
39 {
40 return value;
41 }
42
43 return FNV1a(&str[1], (value ^ static_cast<uint32_t>(str[0])) * Hash::kFNV1aPrime32);
44}
45
46
47/* ------------------------------------------------------------------------- */
54/* ------------------------------------------------------------------------- */
55constexpr uint64_t FNV1a64(const char *str, const uint64_t value = Hash::kFNV1aDefaultValue64) noexcept
56{
57 if (str[0] == '\0')
58 {
59 return value;
60 }
61
62 return FNV1a64(&str[1], (value ^ static_cast<uint64_t>(str[0])) * Hash::kFNV1aPrime64);
63}
64} // namespace MGL::Hash
65#endif // INCGUARD_MGL_HASH_FNV1A_H_1607309087
66
67// vim: et ts=4 sw=4 sts=4
constexpr uint64_t kFNV1aPrime64
64bitハッシュ値の生成に使用する素数
Definition mgl_hash_fnv1a.h:25
constexpr uint32_t kFNV1aPrime32
32bitハッシュ値の生成に使用する素数
Definition mgl_hash_fnv1a.h:21
constexpr uint32_t FNV1a(const char *str, const uint32_t value=Hash::kFNV1aDefaultValue32) noexcept
FNV-1aアルゴリズムで文字列から32bitハッシュ値を取得
Definition mgl_hash_fnv1a.h:36
constexpr uint64_t kFNV1aDefaultValue64
64bitハッシュ値のデフォルト値
Definition mgl_hash_fnv1a.h:23
constexpr uint64_t FNV1a64(const char *str, const uint64_t value=Hash::kFNV1aDefaultValue64) noexcept
FNV-1aアルゴリズムで文字列から64bitハッシュ値を取得
Definition mgl_hash_fnv1a.h:55
constexpr uint32_t kFNV1aDefaultValue32
32bitハッシュ値のデフォルト値
Definition mgl_hash_fnv1a.h:19