[英]Complexity of std::map::insert_or_assign with hint
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? 如果元素已经存在于地图中,则
std::map::insert
或std::map::assign
的时间复杂度是多少? CPP-Reference says that it's the same as emplace_hint
, which says: CPP-Reference表示与
emplace_hint
相同,后者表示:
"amortized constant if the new element is inserted just before hint"
“如果在提示之前插入新元素,则为摊销常量”
But: 但:
lower_bound
or upper_bound
? lower_bound
还是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). 如果键已经存在,那么它甚至比这更简单,不需要将新节点添加到映射中,只需分配即可,因此再次摊销O(1)。 The words "just before hint" suggest that the hint should be slightly above the key mapped, ie an
upper_bound
. 单词“在提示之前”暗示提示应略高于映射的键,即
upper_bound
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.