this method referenced by Java ArrayList.hashCode() method, which takes into account the hashing of nested values
| 264 | // this method referenced by Java ArrayList.hashCode() method, which takes |
| 265 | // into account the hashing of nested values |
| 266 | XXH64_hash_t Map_HashCode |
| 267 | ( |
| 268 | SIValue map |
| 269 | ) { |
| 270 | // sort the map by key, so that {a:1, b:1} and {b:1, a:1} |
| 271 | // have the same hash value |
| 272 | uint key_count = Map_KeyCount(map); |
| 273 | qsort(map.map, key_count, sizeof(Pair), |
| 274 | (int(*)(const void*, const void*))_key_cmp); |
| 275 | |
| 276 | SIType t = T_MAP; |
| 277 | XXH64_hash_t hashCode = XXH64(&t, sizeof(t), 0); |
| 278 | |
| 279 | for(uint i = 0; i < key_count; i++) { |
| 280 | Pair p = map.map[i]; |
| 281 | hashCode = 31 * hashCode + SIValue_HashCode(p.key); |
| 282 | hashCode = 31 * hashCode + SIValue_HashCode(p.val); |
| 283 | } |
| 284 | |
| 285 | return hashCode; |
| 286 | } |
| 287 | |
| 288 | void Map_ToString |
| 289 | ( |
no test coverage detected