2
0
mirror of https://github.com/boostorg/json.git synced 2026-02-21 03:02:13 +00:00

Small fixes and style improvements

This commit is contained in:
Dogan Ulus
2021-03-07 18:28:43 +03:00
parent 40b7acc199
commit 1a3c087f44
3 changed files with 32 additions and 37 deletions

View File

@@ -761,20 +761,18 @@ BOOST_JSON_NS_END
//
//----------------------------------------------------------
namespace std {
std::size_t
hash<::boost::json::array>::operator()(
::boost::json::array const& ja) const noexcept
std::size_t
std::hash<::boost::json::array>::operator()(
::boost::json::array const& ja) const noexcept
{
std::size_t seed = ja.size();
for (const auto& jv : ja) {
seed = boost::json::detail::hash_combine(
seed,
seed = ::boost::json::detail::hash_combine(
seed,
std::hash<::boost::json::value>{}(jv));
}
return seed;
return seed;
};
}
//----------------------------------------------------------

View File

@@ -829,22 +829,21 @@ BOOST_JSON_NS_END
//
//----------------------------------------------------------
namespace std {
std::size_t
hash<::boost::json::object>::operator()(
::boost::json::object const& jo) const noexcept
std::size_t
std::hash<::boost::json::object>::operator()(
::boost::json::object const& jo) const noexcept
{
std::size_t seed = jo.size();
for (const auto& kv_pair : jo) {
const auto hk = std::hash<boost::json::string>{}(kv_pair.key());
const auto hkv = boost::json::detail::hash_combine(
hk,
std::hash<boost::json::value>{}(kv_pair.value()));
seed = boost::json::detail::hash_combine_commutative(seed, hkv);
auto const hk = ::boost::json::detail::digest(
kv_pair.key().data(), kv_pair.key().size(), 0);
auto const hkv = ::boost::json::detail::hash_combine(
hk,
std::hash<::boost::json::value>{}(kv_pair.value()));
seed = ::boost::json::detail::hash_combine_commutative(seed, hkv);
}
return seed;
};
}
//----------------------------------------------------------

View File

@@ -501,10 +501,9 @@ BOOST_JSON_NS_END
//
//----------------------------------------------------------
namespace std {
std::size_t
hash<::boost::json::value>::operator()(
::boost::json::value const& jv) const noexcept
std::size_t
std::hash<::boost::json::value>::operator()(
::boost::json::value const& jv) const noexcept
{
std::size_t seed = static_cast<std::size_t>(jv.kind());
switch (jv.kind()) {
@@ -512,36 +511,35 @@ hash<::boost::json::value>::operator()(
case ::boost::json::kind::null:
return seed;
case ::boost::json::kind::bool_:
return boost::json::detail::hash_combine(
seed,
return ::boost::json::detail::hash_combine(
seed,
hash<bool>{}(jv.get_bool()));
case ::boost::json::kind::int64:
return boost::json::detail::hash_combine(
seed,
return ::boost::json::detail::hash_combine(
seed,
hash<std::int64_t>{}(jv.get_int64()));
case ::boost::json::kind::uint64:
return boost::json::detail::hash_combine(
return ::boost::json::detail::hash_combine(
static_cast<size_t>(::boost::json::kind::int64),
hash<std::uint64_t>{}(jv.get_uint64()));
case boost::json::kind::double_:
return boost::json::detail::hash_combine(
seed,
case ::boost::json::kind::double_:
return ::boost::json::detail::hash_combine(
seed,
hash<double>{}(jv.get_double()));
case ::boost::json::kind::string:
return boost::json::detail::hash_combine(
seed,
return ::boost::json::detail::hash_combine(
seed,
hash<::boost::json::string>{}(jv.get_string()));
case ::boost::json::kind::array:
return boost::json::detail::hash_combine(
seed,
return ::boost::json::detail::hash_combine(
seed,
hash<::boost::json::array>{}(jv.get_array()));
case ::boost::json::kind::object:
return boost::json::detail::hash_combine(
seed,
return ::boost::json::detail::hash_combine(
seed,
hash<::boost::json::object>{}(jv.get_object()));
}
};
}
//----------------------------------------------------------