summaryrefslogtreecommitdiff
path: root/modules/codec/c++/schema_hash.h
diff options
context:
space:
mode:
authorClaudius "keldu" Holeksa <mail@keldu.de>2023-12-04 17:01:04 +0100
committerClaudius "keldu" Holeksa <mail@keldu.de>2023-12-04 17:01:04 +0100
commita863f9af9fff0ecb276c6769149d9672961b7533 (patch)
tree9f7bc499df30e651ae0cc6c2ffca0dd64b4e3769 /modules/codec/c++/schema_hash.h
parent8da0229a7e172a86c023edc6bb25ba803c68f5d3 (diff)
codec: Moving structure around
Diffstat (limited to 'modules/codec/c++/schema_hash.h')
-rw-r--r--modules/codec/c++/schema_hash.h105
1 files changed, 105 insertions, 0 deletions
diff --git a/modules/codec/c++/schema_hash.h b/modules/codec/c++/schema_hash.h
new file mode 100644
index 0000000..5690166
--- /dev/null
+++ b/modules/codec/c++/schema_hash.h
@@ -0,0 +1,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;
+};
+
+}