Iros
 
Loading...
Searching...
No Matches
default_hasher.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/util/exchange.h"
5
6namespace di::container {
8 constexpr void write(vocab::Span<byte const> data) noexcept {
9 // For now, this is a simple hash function. This is apparently used by Java.
10 // See https://computinglife.wordpress.com/2008/11/20/why-do-hash-functions-use-prime-numbers/.
11 for (auto const byte : data) {
12 m_hash = (m_hash * 31U) + di::to_integer<u8>(byte);
13 }
14 }
15
16 constexpr auto finish() noexcept -> u64 { return util::exchange(m_hash, 0); }
17
18private:
19 u64 m_hash { 0 };
20};
21}
22
23namespace di {
25}
Definition span_forward_declaration.h:10
Definition sequence.h:12
constexpr auto data
Definition data.h:51
__UINT64_TYPE__ u64
Definition integers.h:12
constexpr auto exchange(T &object, U &&new_value) -> T
Definition exchange.h:8
Definition zstring_parser.h:9
Definition default_hasher.h:7
constexpr void write(vocab::Span< byte const > data) noexcept
Definition default_hasher.h:8
constexpr auto finish() noexcept -> u64
Definition default_hasher.h:16