1#include "duckdb/common/checksum.hpp"
2#include "duckdb/common/types/hash.hpp"
3
4namespace duckdb {
5
6hash_t Checksum(uint64_t x) {
7 return x * UINT64_C(0xbf58476d1ce4e5b9);
8}
9
10uint64_t Checksum(uint8_t *buffer, size_t size) {
11 uint64_t result = 5381;
12 uint64_t *ptr = reinterpret_cast<uint64_t *>(buffer);
13 size_t i;
14 // for efficiency, we first checksum uint64_t values
15 for (i = 0; i < size / 8; i++) {
16 result ^= Checksum(x: ptr[i]);
17 }
18 if (size - i * 8 > 0) {
19 // the remaining 0-7 bytes we hash using a string hash
20 result ^= Hash(val: buffer + i * 8, size: size - i * 8);
21 }
22 return result;
23}
24
25} // namespace duckdb
26