From d94c31fee53c3c7df981cf44a54dd722d7fc122c Mon Sep 17 00:00:00 2001 From: "Claudius \"keldu\" Holeksa" Date: Mon, 15 Jan 2024 17:04:16 +0100 Subject: codec: hash functionality added --- modules/codec/c++/schema_hash.h | 104 ++++++++-------------------------------- 1 file changed, 21 insertions(+), 83 deletions(-) (limited to 'modules/codec/c++/schema_hash.h') diff --git a/modules/codec/c++/schema_hash.h b/modules/codec/c++/schema_hash.h index 5690166..a7f482f 100644 --- a/modules/codec/c++/schema_hash.h +++ b/modules/codec/c++/schema_hash.h @@ -1,105 +1,43 @@ #pragma once +#include #include "schema.h" +#include "data.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{}(v) + 0x9e3779b9 + (seed<<6) + (seed >> 2)); } }; +template +struct schema_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){ + seed = schema_hash_combine::apply(seed, static_cast(view[i])); + } + return seed; + } +}; + template struct schema_hash { static_assert(always_false, "Not schema_hashable"); }; -template<> -struct schema_hash> { - static constexpr uint64_t base_value = 0u; -}; - -template<> -struct schema_hash> { - static constexpr uint64_t base_value = 1u; -}; - -template<> -struct schema_hash> { - static constexpr uint64_t base_value = 2u; -}; - -template<> -struct schema_hash> { - static constexpr uint64_t base_value = 3u; -}; - -template<> -struct schema_hash> { - static constexpr uint64_t base_value = 4u; -}; - -template<> -struct schema_hash> { - static constexpr uint64_t base_value = 5u; -}; - -template<> -struct schema_hash> { - static constexpr uint64_t base_value = 6u; -}; - -template<> -struct schema_hash> { - static constexpr uint64_t base_value = 7u; -}; - -template<> -struct schema_hash> { - static constexpr uint64_t base_value = 8u; -}; - -template<> -struct schema_hash> { - static constexpr uint64_t base_value = 9u; -}; - -template -struct schema_hash> { - static constexpr uint64_t base_value = 10u; -}; - -template -struct schema_hash...>> { - static constexpr uint64_t base_value = 11u; -}; - -template -struct schema_hash...>> { - static constexpr uint64_t base_value = 12u; -}; - -template -struct schema_hash> { - static constexpr uint64_t base_value = 13u; -}; - template<> struct schema_hash { - static constexpr uint64_t base_value = 14u; -}; + using Schema = schema::String; -template -struct schema_hash> { - static constexpr uint64_t base_value = 15u; -}; - -template -struct schema_hash> { - static constexpr uint64_t base_value = 16u; + 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))); + } + return seed; + } }; } -- cgit v1.2.3