See https://en.cppreference.com/w/cpp/container/map/erase for reference.
How is erasing a single iterator able to be done in amortized constant time? This seems to imply that the rebalancing of the red black tree can be done in constant time.
See https://en.cppreference.com/w/cpp/container/map/erase for reference.
How is erasing a single iterator able to be done in amortized constant time? This seems to imply that the rebalancing of the red black tree can be done in constant time.
Amortized constant time doesn't mean that any single operation takes constant time, but that, over many such operations, the non-constant overhead of some operations amortizes to overall constant time.
In other words, if you use erase
repeatedly to clear the entire map, that loop finishes in linear time in the number of elements, and thus constant time per element.
For a more thorough analysis, cs.stackexchange.com would probably be a more appropriate place.