From 2dd333c909748e7e735be3e302c8e7a0993bbbec Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 22 Jan 2024 19:05:23 +0100 Subject: codec: Adding more hashing cases --- modules/codec/c++/schema_hash.h | 67 +++++++++++++++++++++++++++++++++++++++++ modules/codec/tests/schema.cpp | 7 ++++- 2 files changed, 73 insertions(+), 1 deletion(-) (limited to 'modules/codec') diff --git a/modules/codec/c++/schema_hash.h b/modules/codec/c++/schema_hash.h index 48e8d6c..29afa5e 100644 --- a/modules/codec/c++/schema_hash.h +++ b/modules/codec/c++/schema_hash.h @@ -100,6 +100,31 @@ struct schema_hash_seed> { } }; +template +struct schema_hash_seed> { + using Schema = schema::Tuple; + + template + static constexpr uint32_t apply_ele(uint32_t seed){ + using Type = typename parameter_pack_type::type; + + seed = schema_hash_seed::apply(seed); + if constexpr ( (i+1) < sizeof...(T) ){ + return apply_ele(seed); + } + return seed; + } + + + static constexpr uint32_t apply(uint32_t seed){ + seed = hash_literal::apply(seed); + if constexpr (sizeof...(T) > 0){ + seed = apply_ele<0>(seed); + } + return seed; + } +}; + template struct schema_hash_seed...>> { using Schema = schema::Struct...>; @@ -129,6 +154,48 @@ struct schema_hash_seed...>> { } }; +template +struct schema_hash_seed> { + using Schema = schema::Function; + + static constexpr uint32_t apply(uint32_t seed){ + seed = hash_literal::apply(seed); + seed = schema_hash_seed::apply(seed); + seed = schema_hash_seed::apply(seed); + return seed; + } +}; + +template +struct schema_hash_seed...>> { + using Schema = schema::Interface...>; + + template + static constexpr uint32_t apply_ele(uint32_t seed){ + using Type = typename parameter_pack_type::type; + constexpr string_literal Lit = parameter_key_pack_type::literal; + using MemberT = schema::Member; + + seed = hash_literal::apply(seed); + seed = schema_hash_seed::apply(seed); + seed = hash_literal::apply(seed); + + if constexpr ( (i+1) < sizeof...(T) ){ + return apply_ele(seed); + } + + return seed; + } + + static constexpr uint32_t apply(uint32_t seed){ + seed = hash_literal::apply(seed); + if constexpr ( sizeof...(T) > 0){ + seed = apply_ele<0>(seed); + } + return seed; + } +}; + template struct schema_hash { static constexpr uint32_t apply() { diff --git a/modules/codec/tests/schema.cpp b/modules/codec/tests/schema.cpp index 71e806d..31c68f2 100644 --- a/modules/codec/tests/schema.cpp +++ b/modules/codec/tests/schema.cpp @@ -44,6 +44,10 @@ struct schema_hash_test_multi { namespace schema { using namespace saw::schema; + +using HashIface = Interface< + Member, UInt32>, "foo"> +>; } SAW_TEST("Schema Hashes"){ @@ -62,7 +66,8 @@ SAW_TEST("Schema Hashes"){ schema_test_pair, schema_test_pair, schema_test_pair, - schema_test_pair + schema_test_pair, + schema_test_pair >::check(); } } -- cgit v1.2.3