| 324 } |
324 } |
| 325 |
325 |
| 326 int cxMapUnionSimple(CxMap *dst, const CxMap *src) { |
326 int cxMapUnionSimple(CxMap *dst, const CxMap *src) { |
| 327 return cxMapUnion(dst, src, use_simple_clone_func(src)); |
327 return cxMapUnion(dst, src, use_simple_clone_func(src)); |
| 328 } |
328 } |
| |
329 |
| |
330 int cxMapCompare(const CxMap *map, const CxMap *other) { |
| |
331 // compare map sizes |
| |
332 const size_t size_left = cxMapSize(map); |
| |
333 const size_t size_right = cxMapSize(other); |
| |
334 if (size_left < size_right) { |
| |
335 return -1; |
| |
336 } else if (size_left > size_right) { |
| |
337 return 1; |
| |
338 } |
| |
339 |
| |
340 // iterate through the first map |
| |
341 CxMapIterator iter = cxMapIterator(map); |
| |
342 cx_foreach(const CxMapEntry *, entry, iter) { |
| |
343 const void *value_left = entry->value; |
| |
344 const void *value_right = cxMapGet(other, *entry->key); |
| |
345 // if the other map does not have the key, we are done |
| |
346 if (value_right == NULL) { |
| |
347 return -1; |
| |
348 } |
| |
349 // compare the values |
| |
350 const int d = map->collection.cmpfunc(value_left, value_right); |
| |
351 if (d != 0) { |
| |
352 return d; |
| |
353 } |
| |
354 } |
| |
355 |
| |
356 return 0; |
| |
357 } |