| 67 | |
| 68 | |
| 69 | static inline uint64_t HashRapidValue(const rapidjson::Value& val) |
| 70 | { |
| 71 | const auto type = static_cast<std::size_t>(val.GetType()); |
| 72 | switch (val.GetType()) |
| 73 | { |
| 74 | case rapidjson::kNullType: |
| 75 | case rapidjson::kFalseType: |
| 76 | { |
| 77 | return combine(type, 0); |
| 78 | } |
| 79 | case rapidjson::kObjectType: |
| 80 | { |
| 81 | auto seed = combine(type, val.MemberCount()); |
| 82 | for (const auto& element : val.GetObj()) |
| 83 | { |
| 84 | const auto h = HashBytes(element.name.GetString(), element.name.GetStringLength()); |
| 85 | seed = combine(seed, h); |
| 86 | seed = combine(seed, HashRapidValue(element.value)); |
| 87 | } |
| 88 | return seed; |
| 89 | } |
| 90 | case rapidjson::kArrayType: |
| 91 | { |
| 92 | auto seed = combine(type, val.Size()); |
| 93 | for (const auto& element : val.GetArray()) |
| 94 | { |
| 95 | seed = combine(seed, HashRapidValue(element)); |
| 96 | } |
| 97 | return seed; |
| 98 | } |
| 99 | case rapidjson::kStringType: |
| 100 | { |
| 101 | return combine(type, HashBytes(val.GetString(), val.GetStringLength())); |
| 102 | } |
| 103 | case rapidjson::kTrueType: |
| 104 | { |
| 105 | return combine(type, 1); |
| 106 | } |
| 107 | case rapidjson::kNumberType: |
| 108 | { |
| 109 | if (val.IsInt64()) |
| 110 | { |
| 111 | return combine(type, static_cast<size_t>(val.GetInt64())); |
| 112 | } |
| 113 | else if (val.IsUint64()) |
| 114 | { |
| 115 | return combine(type, val.GetUint64()); |
| 116 | } |
| 117 | else if (val.IsUint()) |
| 118 | { |
| 119 | return combine(type, static_cast<size_t>(val.GetUint())); |
| 120 | } |
| 121 | else if (val.IsInt()) |
| 122 | { |
| 123 | return combine(type, static_cast<size_t>(val.GetInt())); |
| 124 | } |
| 125 | else |
| 126 | { |