MCPcopy Create free account
hub / github.com/dobin/RedEdr / hash

Function hash

RedEdrShared/json.hpp:6048–6133  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6046 */
6047 template<typename BasicJsonType>
6048 std::size_t hash(const BasicJsonType& j)
6049 {
6050 using string_t = typename BasicJsonType::string_t;
6051 using number_integer_t = typename BasicJsonType::number_integer_t;
6052 using number_unsigned_t = typename BasicJsonType::number_unsigned_t;
6053 using number_float_t = typename BasicJsonType::number_float_t;
6054
6055 const auto type = static_cast<std::size_t>(j.type());
6056 switch (j.type())
6057 {
6058 case BasicJsonType::value_t::null:
6059 case BasicJsonType::value_t::discarded:
6060 {
6061 return combine(type, 0);
6062 }
6063
6064 case BasicJsonType::value_t::object:
6065 {
6066 auto seed = combine(type, j.size());
6067 for (const auto& element : j.items())
6068 {
6069 const auto h = std::hash<string_t>{}(element.key());
6070 seed = combine(seed, h);
6071 seed = combine(seed, hash(element.value()));
6072 }
6073 return seed;
6074 }
6075
6076 case BasicJsonType::value_t::array:
6077 {
6078 auto seed = combine(type, j.size());
6079 for (const auto& element : j)
6080 {
6081 seed = combine(seed, hash(element));
6082 }
6083 return seed;
6084 }
6085
6086 case BasicJsonType::value_t::string:
6087 {
6088 const auto h = std::hash<string_t>{}(j.template get_ref<const string_t&>());
6089 return combine(type, h);
6090 }
6091
6092 case BasicJsonType::value_t::boolean:
6093 {
6094 const auto h = std::hash<bool>{}(j.template get<bool>());
6095 return combine(type, h);
6096 }
6097
6098 case BasicJsonType::value_t::number_integer:
6099 {
6100 const auto h = std::hash<number_integer_t>{}(j.template get<number_integer_t>());
6101 return combine(type, h);
6102 }
6103
6104 case BasicJsonType::value_t::number_unsigned:
6105 {

Callers 1

operator()Function · 0.85

Calls 6

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

Tested by

no test coverage detected