MCPcopy Create free account
hub / github.com/OpenFodder/openfodder / hash

Function hash

Source/Utils/json.hpp:4613–4697  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4611 */
4612 template<typename BasicJsonType>
4613 std::size_t hash(const BasicJsonType& j)
4614 {
4615 using string_t = typename BasicJsonType::string_t;
4616 using number_integer_t = typename BasicJsonType::number_integer_t;
4617 using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
4618 using number_float_t = typename BasicJsonType::number_float_t;
4619
4620 const auto type = static_cast<std::size_t>(j.type());
4621 switch (j.type())
4622 {
4623 case BasicJsonType::value_t::null:
4624 case BasicJsonType::value_t::discarded:
4625 {
4626 return combine(type, 0);
4627 }
4628
4629 case BasicJsonType::value_t::object:
4630 {
4631 auto seed = combine(type, j.size());
4632 for (const auto& element : j.items())
4633 {
4634 const auto h = std::hash<string_t>{}(element.key());
4635 seed = combine(seed, h);
4636 seed = combine(seed, hash(element.value()));
4637 }
4638 return seed;
4639 }
4640
4641 case BasicJsonType::value_t::array:
4642 {
4643 auto seed = combine(type, j.size());
4644 for (const auto& element : j)
4645 {
4646 seed = combine(seed, hash(element));
4647 }
4648 return seed;
4649 }
4650
4651 case BasicJsonType::value_t::string:
4652 {
4653 const auto h = std::hash<string_t>{}(j.template get_ref<const string_t&>());
4654 return combine(type, h);
4655 }
4656
4657 case BasicJsonType::value_t::boolean:
4658 {
4659 const auto h = std::hash<bool>{}(j.template get<bool>());
4660 return combine(type, h);
4661 }
4662
4663 case BasicJsonType::value_t::number_integer:
4664 {
4665 const auto h = std::hash<number_integer_t>{}(j.template get<number_integer_t>());
4666 return combine(type, h);
4667 }
4668
4669 case nlohmann::detail::value_t::number_unsigned:
4670 {

Callers 1

operator()Method · 0.70

Calls 8

combineFunction · 0.85
typeMethod · 0.80
get_binaryMethod · 0.80
has_subtypeMethod · 0.80
subtypeMethod · 0.80
sizeMethod · 0.45
keyMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected