12 inline std::size_t combine(std::size_t seed, std::size_t h) noexcept
14 seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U);
29 template<
typename BasicJsonType>
30 std::size_t
hash(
const BasicJsonType& j)
32 using string_t =
typename BasicJsonType::string_t;
33 using number_integer_t =
typename BasicJsonType::number_integer_t;
34 using number_unsigned_t =
typename BasicJsonType::number_unsigned_t;
35 using number_float_t =
typename BasicJsonType::number_float_t;
37 const auto type =
static_cast<std::size_t
>(j.type());
40 case BasicJsonType::value_t::null:
41 case BasicJsonType::value_t::discarded:
43 return combine(type, 0);
46 case BasicJsonType::value_t::object:
48 auto seed = combine(type, j.size());
49 for (
const auto& element : j.items())
51 const auto h = std::hash<string_t> {}(element.key());
52 seed = combine(seed, h);
53 seed = combine(seed,
hash(element.value()));
58 case BasicJsonType::value_t::array:
60 auto seed = combine(type, j.size());
61 for (
const auto& element : j)
63 seed = combine(seed,
hash(element));
68 case BasicJsonType::value_t::string:
70 const auto h = std::hash<string_t> {}(j.template get_ref<const string_t&>());
71 return combine(type, h);
74 case BasicJsonType::value_t::boolean:
76 const auto h = std::hash<bool> {}(j.template get<bool>());
77 return combine(type, h);
80 case BasicJsonType::value_t::number_integer:
82 const auto h = std::hash<number_integer_t> {}(j.template get<number_integer_t>());
83 return combine(type, h);
88 const auto h = std::hash<number_unsigned_t> {}(j.template get<number_unsigned_t>());
89 return combine(type, h);
94 const auto h = std::hash<number_float_t> {}(j.template get<number_float_t>());
95 return combine(type, h);
100 auto seed = combine(type, j.get_binary().size());
101 const auto h = std::hash<bool> {}(j.get_binary().has_subtype());
102 seed = combine(seed, h);
103 seed = combine(seed, j.get_binary().subtype());
104 for (
const auto byte : j.get_binary())
106 seed = combine(seed, std::hash<std::uint8_t> {}(byte));
@ binary
binary array (ordered collection of bytes)
@ number_float
number value (floating-point)
@ number_unsigned
number value (unsigned integer)
std::size_t hash(const BasicJsonType &j)
hash a JSON value
Definition: hash.hpp:30
namespace for Niels Lohmann
Definition: adl_serializer.hpp:9