From 634f55ceed45197e743c2d1c3df0c97c6f8888ae Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Tue, 16 Jan 2024 15:26:46 +0100 Subject: codec: Adding schema hashes and testing --- modules/codec/c++/schema_hash.h | 60 ++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 9 deletions(-) (limited to 'modules/codec/c++') diff --git a/modules/codec/c++/schema_hash.h b/modules/codec/c++/schema_hash.h index a7f482f..8f66fbf 100644 --- a/modules/codec/c++/schema_hash.h +++ b/modules/codec/c++/schema_hash.h @@ -2,7 +2,6 @@ #include #include "schema.h" -#include "data.h" namespace saw { struct schema_hash_combine { @@ -12,7 +11,7 @@ struct schema_hash_combine { }; template -struct schema_hash_literal { +struct 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){ @@ -23,21 +22,64 @@ struct schema_hash_literal { }; template -struct schema_hash { +struct schema_hash_seed { static_assert(always_false, "Not schema_hashable"); }; template<> -struct schema_hash { +struct schema_hash_seed { + using Schema = schema::SignedInteger; + + static constexpr uint64_t apply(uint64_t seed){ + return hash_literal::apply(seed); + } +}; + +template<> +struct schema_hash_seed { + using Schema = schema::UnsignedInteger; + + static constexpr uint64_t apply(uint64_t seed){ + return hash_literal::apply(seed); + } +}; + +template<> +struct schema_hash_seed { + using Schema = schema::FloatingPoint; + + static constexpr uint64_t apply(uint64_t seed){ + return hash_literal::apply(seed); + } +}; + +template<> +struct schema_hash_seed { using Schema = schema::String; - static constexpr uint64_t apply(uint64_t seed, const data& val){ - seed = schema_hash_literal::apply(seed); - for(size_t i = 0; i < val.size(); ++i){ - seed = schema_hash_combine::apply(seed, static_cast(val.at(i))); - } + static constexpr uint64_t apply(uint64_t seed){ + return hash_literal::apply(seed); + } +}; + +template +struct schema_hash_seed> { + using Schema = schema::Primitive; + + static constexpr uint64_t apply(uint64_t seed){ + seed = hash_literal::apply(seed); + seed = schema_hash_seed

::apply(seed); + seed = schema_hash_combine::apply(seed, N); return seed; } }; +template +struct schema_hash { + static constexpr uint64_t apply() { + constexpr uint64_t seed = 0; + return schema_hash_seed::apply(seed); + } +}; + } -- cgit v1.2.3