#pragma once #include #include "schema.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 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_seed { static_assert(always_false, "Not schema_hashable"); }; template<> 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){ 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); } }; }