RSTools 3.1.0
Versatile C++20 utility library
Loading...
Searching...
No Matches
Hash.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <string_view>
6
7namespace RST::String {
8
11
13 [[nodiscard]] constexpr std::uint64_t hash(std::string_view str) noexcept
14 {
15 std::uint64_t hash = 0xcbf29ce484222325ull;
16 for (const char c : str) {
17 hash ^= static_cast<unsigned char>(c);
18 hash *= 0x100000001b3ull;
19 }
20 return hash;
21 }
23
25 namespace Literals {
26
28 [[nodiscard]] consteval std::uint64_t operator""_hash(const char* str, std::size_t size) noexcept
29 {
30 return hash(std::string_view(str, size));
31 }
32 }
33}
String helpers: case, trimming, splitting, joining, replacing, parsing and hashing.
Definition Char.hpp:3
constexpr std::uint64_t hash(std::string_view str) noexcept
64-bit FNV-1a hash, usable at compile time.
Definition Hash.hpp:13
std::optional< T > parseNumber(std::string_view text, int base=10) noexcept
Parses text as a number, or returns std::nullopt if it is not entirely one.
Definition Convert.hpp:23