summaryrefslogtreecommitdiff
path: root/modules/codec/schema_hash.h
blob: 56901666a0d0d089b66a2f5231d22c5c96c74d5f (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#pragma once

#include "schema.h"

namespace saw {
struct schema_hash_combine {
		static constexpr uint64_t apply(uint64_t seed, uint64_t v){
				return (seed ^ v) * 1099511628211u;


				return seed ^( std::hash<uint64_t>{}(v) + 0x9e3779b9 + (seed<<6) + (seed >> 2));
		}
};

template<typename Schema>
struct schema_hash {
		static_assert(always_false<Schema>, "Not schema_hashable");
};

template<>
struct schema_hash<schema::Primitive<schema::SignedInteger,1>> {
		static constexpr uint64_t base_value = 0u;
};

template<>
struct schema_hash<schema::Primitive<schema::SignedInteger,2>> {
		static constexpr uint64_t base_value = 1u;
};

template<>
struct schema_hash<schema::Primitive<schema::SignedInteger,4>> {
		static constexpr uint64_t base_value = 2u;
};

template<>
struct schema_hash<schema::Primitive<schema::SignedInteger,8>> {
		static constexpr uint64_t base_value = 3u;
};

template<>
struct schema_hash<schema::Primitive<schema::UnsignedInteger,1>> {
		static constexpr uint64_t base_value = 4u;
};

template<>
struct schema_hash<schema::Primitive<schema::UnsignedInteger,2>> {
		static constexpr uint64_t base_value = 5u;
};

template<>
struct schema_hash<schema::Primitive<schema::UnsignedInteger,4>> {
		static constexpr uint64_t base_value = 6u;
};

template<>
struct schema_hash<schema::Primitive<schema::UnsignedInteger,8>> {
		static constexpr uint64_t base_value = 7u;
};

template<>
struct schema_hash<schema::Primitive<schema::FloatingPoint,4>> {
		static constexpr uint64_t base_value = 8u;
};

template<>
struct schema_hash<schema::Primitive<schema::FloatingPoint,8>> {
		static constexpr uint64_t base_value = 9u;
};

template<typename... T>
struct schema_hash<schema::Tuple<T...>> {
		static constexpr uint64_t base_value = 10u;
};

template<typename... T, string_literal Literal>
struct schema_hash<schema::Struct<schema::Member<T,Literal>...>> {
		static constexpr uint64_t base_value = 11u;
};

template<typename... T, string_literal Literal>
struct schema_hash<schema::Union<schema::Member<T,Literal>...>> {
		static constexpr uint64_t base_value = 12u;
};

template<typename T, size_t Dim>
struct schema_hash<schema::Array<T,Dim>> {
		static constexpr uint64_t base_value = 13u;
};

template<>
struct schema_hash<schema::String> {
		static constexpr uint64_t base_value = 14u;
};

template<typename T, typename N>
struct schema_hash<schema::Wrapper<T,N>> {
		static constexpr uint64_t base_value = 15u;
};

template<typename T, size_t... Dims>
struct schema_hash<schema::FixedArray<T,Dims...>> {
		static constexpr uint64_t base_value = 16u;
};

}