src/hash_map.c

changeset 1429
6e0c3a8a914a
parent 1400
7bc88ae62755
equal deleted inserted replaced
1428:0ac4aa1737fd 1429:6e0c3a8a914a
279 return iter->elem != NULL; 279 return iter->elem != NULL;
280 } 280 }
281 281
282 static void cx_hash_map_iter_next(void *it) { 282 static void cx_hash_map_iter_next(void *it) {
283 CxMapIterator *iter = it; 283 CxMapIterator *iter = it;
284 CxMap *map = iter->map.m; 284 CxMap *map = iter->map;
285 struct cx_hash_map_s *hmap = (struct cx_hash_map_s *) map; 285 struct cx_hash_map_s *hmap = (struct cx_hash_map_s *) map;
286 struct cx_hash_map_element_s *elm = iter->elem; 286 struct cx_hash_map_element_s *elm = iter->elem;
287 287
288 // remove current element, if asked 288 // remove current element, if asked
289 if (iter->base.remove) { 289 if (iter->base.remove) {
327 // copy data to a location where the iterator can point to 327 // copy data to a location where the iterator can point to
328 // we need to do it here, because the iterator function call 328 // we need to do it here, because the iterator function call
329 // must not modify the iterator (the parameter is const) 329 // must not modify the iterator (the parameter is const)
330 if (elm != NULL) { 330 if (elm != NULL) {
331 iter->entry.key = &elm->key; 331 iter->entry.key = &elm->key;
332 if (iter->map.c->collection.store_pointer) { 332 if (map->collection.store_pointer) {
333 iter->entry.value = *(void **) elm->data; 333 iter->entry.value = *(void **) elm->data;
334 } else { 334 } else {
335 iter->entry.value = elm->data; 335 iter->entry.value = elm->data;
336 } 336 }
337 } 337 }
341 const CxMap *map, 341 const CxMap *map,
342 enum cx_map_iterator_type type 342 enum cx_map_iterator_type type
343 ) { 343 ) {
344 CxMapIterator iter; 344 CxMapIterator iter;
345 345
346 iter.map.c = map; 346 iter.map = (CxMap*) map;
347 iter.elem_count = map->collection.size; 347 iter.elem_count = map->collection.size;
348 348
349 switch (type) { 349 switch (type) {
350 case CX_MAP_ITERATOR_PAIRS: 350 case CX_MAP_ITERATOR_PAIRS:
351 iter.elem_size = sizeof(CxMapEntry); 351 iter.elem_size = sizeof(CxMapEntry);
364 } 364 }
365 365
366 iter.base.valid = cx_hash_map_iter_valid; 366 iter.base.valid = cx_hash_map_iter_valid;
367 iter.base.next = cx_hash_map_iter_next; 367 iter.base.next = cx_hash_map_iter_next;
368 iter.base.remove = false; 368 iter.base.remove = false;
369 iter.base.mutating = false; 369 iter.base.allow_remove = true;
370 370
371 iter.slot = 0; 371 iter.slot = 0;
372 iter.index = 0; 372 iter.index = 0;
373 373
374 if (map->collection.size > 0) { 374 if (map->collection.size > 0) {

mercurial