1#include "duckdb/common/types/hash.hpp"
2#include "duckdb/common/types/string_type.hpp"
3
4#include "duckdb/common/exception.hpp"
5
6#include <functional>
7
8using namespace std;
9
10namespace duckdb {
11
12template <> hash_t Hash(uint64_t val) {
13 return murmurhash64(val);
14}
15
16template <> hash_t Hash(int64_t val) {
17 return murmurhash64((uint64_t)val);
18}
19
20template <> hash_t Hash(float val) {
21 return std::hash<float>{}(val);
22}
23
24template <> hash_t Hash(double val) {
25 return std::hash<double>{}(val);
26}
27
28template <> hash_t Hash(const char *str) {
29 hash_t hash = 5381;
30 hash_t c;
31
32 while ((c = *str++)) {
33 hash = ((hash << 5) + hash) + c;
34 }
35
36 return hash;
37}
38
39template <> hash_t Hash(string_t val) {
40 return Hash(val.GetData(), val.GetSize());
41}
42
43template <> hash_t Hash(char *val) {
44 return Hash<const char *>(val);
45}
46
47hash_t Hash(const char *val, size_t size) {
48 hash_t hash = 5381;
49
50 for (size_t i = 0; i < size; i++) {
51 hash = ((hash << 5) + hash) + val[i];
52 }
53
54 return hash;
55}
56
57hash_t Hash(char *val, size_t size) {
58 return Hash((const char *)val, size);
59}
60
61hash_t Hash(uint8_t *val, size_t size) {
62 return Hash((const char *)val, size);
63}
64
65} // namespace duckdb
66