What is the time complexity of std::map::insert
or std::map::assign
with hint provided in the case that the element already exists in the map? CPP-Reference says that it's the same as emplace_hint
, which says:
"amortized constant if the new element is inserted just before hint"
But:
lower_bound
or upper_bound
? If the key already exists, then it is even simpler than that, no need to add new node into the map, just an assignment, so again, ammortized O(1). The words "just before hint" suggest that the hint should be slightly above the key mapped, ie an upper_bound
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.