| 214 | } |
| 215 | |
| 216 | int Map_Compare |
| 217 | ( |
| 218 | SIValue mapA, |
| 219 | SIValue mapB, |
| 220 | int *disjointOrNull |
| 221 | ) { |
| 222 | int order = 0; |
| 223 | Map A = mapA.map; |
| 224 | Map B = mapB.map; |
| 225 | uint key_count = Map_KeyCount(mapA); |
| 226 | uint A_key_count = Map_KeyCount(mapA); |
| 227 | uint B_key_count = Map_KeyCount(mapB); |
| 228 | |
| 229 | if(A_key_count != B_key_count) { |
| 230 | if(A_key_count > B_key_count) return 1; |
| 231 | else return -1; |
| 232 | } |
| 233 | |
| 234 | // sort both maps |
| 235 | qsort(A, A_key_count, sizeof(Pair), |
| 236 | (int(*)(const void*, const void*))_key_cmp); |
| 237 | qsort(B, B_key_count, sizeof(Pair), |
| 238 | (int(*)(const void*, const void*))_key_cmp); |
| 239 | |
| 240 | // element-wise key comparison |
| 241 | for(uint i = 0; i < key_count; i++) { |
| 242 | // if the maps contain different keys, order in favor |
| 243 | // of the first lexicographically greater key |
| 244 | order = SIValue_Compare(A[i].key, B[i].key, NULL); |
| 245 | if(order != 0) return order; |
| 246 | } |
| 247 | |
| 248 | // element-wise value comparison |
| 249 | for(uint i = 0; i < key_count; i++) { |
| 250 | // key lookup succeeded; compare values |
| 251 | order = SIValue_Compare(A[i].val, B[i].val, disjointOrNull); |
| 252 | if(disjointOrNull && (*disjointOrNull == COMPARED_NULL || |
| 253 | *disjointOrNull == DISJOINT)) { |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | if(order != 0) return order; |
| 258 | } |
| 259 | |
| 260 | // maps are equal |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | // this method referenced by Java ArrayList.hashCode() method, which takes |
| 265 | // into account the hashing of nested values |
no test coverage detected