diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-11-20 17:41:18 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2023-11-20 17:41:18 +0100 |
commit | 3624d106f08b906a1a3d5e99a7e00eda212ad85b (patch) | |
tree | 171d4467cc8efd4cb0cea25c7291657e6d58bf85 /c++ | |
parent | e7fb9cea480b012174e0a846c0159a7b102ebdcc (diff) |
codec: Some initial work on schema hashes
Diffstat (limited to 'c++')
-rw-r--r-- | c++/codec/schema_hash.h | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/c++/codec/schema_hash.h b/c++/codec/schema_hash.h new file mode 100644 index 0000000..5690166 --- /dev/null +++ b/c++/codec/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; +}; + +} |