src/map.c

changeset 1579
0393c67556ec
parent 1479
ac1baaed2fd7
child 1587
7156d6699410
equal deleted inserted replaced
1578:fb73c4d69317 1579:0393c67556ec
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 }

mercurial