ITERATOR INVALIDATION
An iterator that has been invalidated must be repositioned with dict_itor_first(), dict_itor_last() or dict_itor_search() before further use. Freeing a dictionary leaves all of its iterators unusable; they may only be freed.
Trees and the skip list:
- Inserting never invalidates an iterator.
- Removing an element (by key, by dict_itor_remove() or by dict_clear()) invalidates iterators positioned on that element; using them is undefined. In every tree except tr_tree, removing a key whose node has two children moves the key and datum of an in-order neighbour (the successor in rb_tree and sp_tree, the successor or predecessor in hb_tree, pr_tree and wb_tree) into that node and frees the neighbour's node instead. So an iterator positioned on that neighbour is invalidated as well, and one positioned on the removed key is left on the neighbour.
Hash tables: