#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 ^( 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 { 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))); } return seed; } }; }