blob: a7f482fecbab8cb7015e9cccbc9dc137290c7b8a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
#pragma once
#include <forstio/string_literal.h>
#include "schema.h"
#include "data.h"
namespace saw {
struct schema_hash_combine {
static constexpr uint64_t apply(uint64_t seed, uint64_t v){
return seed ^( std::hash<uint64_t>{}(v) + 0x9e3779b9 + (seed<<6) + (seed >> 2));
}
};
template<string_literal lit>
struct schema_hash_literal {
static constexpr uint64_t apply(uint64_t seed){
constexpr std::string_view view = lit.view();
for(uint64_t i = 0; i < view.size(); ++i){
seed = schema_hash_combine::apply(seed, static_cast<uint64_t>(view[i]));
}
return seed;
}
};
template<typename Schema>
struct schema_hash {
static_assert(always_false<Schema>, "Not schema_hashable");
};
template<>
struct schema_hash<schema::String> {
using Schema = schema::String;
static constexpr uint64_t apply(uint64_t seed, const data<Schema>& val){
seed = schema_hash_literal<Schema::name>::apply(seed);
for(size_t i = 0; i < val.size(); ++i){
seed = schema_hash_combine::apply(seed, static_cast<uint64_t>(val.at(i)));
}
return seed;
}
};
}
|