src/map.c

changeset 1466
a58c65d31342
parent 1450
09a73312d5ec
equal deleted inserted replaced
1465:dc886f1a6155 1466:a58c65d31342
166 166
167 int cxMapDifference(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend, 167 int cxMapDifference(CxMap *dst, const CxMap *minuend, const CxMap *subtrahend,
168 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { 168 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) {
169 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; 169 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator;
170 170
171 // if the destination map already contains something,
172 // remove what does not belong to the difference
173 CxMapIterator dst_iter = cxMapIteratorKeys(dst);
174 cx_foreach(const CxHashKey *, key, dst_iter) {
175 if (cxMapContains(subtrahend, *key)) {
176 cxIteratorFlagRemoval(dst_iter);
177 }
178 }
179
180 CxMapIterator src_iter = cxMapIterator(minuend); 171 CxMapIterator src_iter = cxMapIterator(minuend);
181 cx_foreach(const CxMapEntry *, entry, src_iter) { 172 cx_foreach(const CxMapEntry *, entry, src_iter) {
182 if (cxMapContains(subtrahend, *entry->key)) { 173 if (cxMapContains(subtrahend, *entry->key)) {
183 continue; 174 continue;
184 } 175 }
201 192
202 int cxMapListDifference(CxMap *dst, const CxMap *src, const CxList *keys, 193 int cxMapListDifference(CxMap *dst, const CxMap *src, const CxList *keys,
203 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) { 194 cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data) {
204 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator; 195 if (clone_allocator == NULL) clone_allocator = cxDefaultAllocator;
205 196
206 // if the destination map already contains something,
207 // remove what does not belong to the difference
208 CxMapIterator dst_iter = cxMapIteratorKeys(dst);
209 cx_foreach(const CxHashKey *, key, dst_iter) {
210 if (cxListContains(keys, key)) {
211 cxIteratorFlagRemoval(dst_iter);
212 }
213 }
214
215 CxMapIterator src_iter = cxMapIterator(src); 197 CxMapIterator src_iter = cxMapIterator(src);
216 cx_foreach(const CxMapEntry *, entry, src_iter) { 198 cx_foreach(const CxMapEntry *, entry, src_iter) {
217 if (cxListContains(keys, entry->key)) { 199 if (cxListContains(keys, entry->key)) {
218 continue; 200 continue;
219 } 201 }

mercurial