std::map::erase() - which overload is faster?

我的未来我决定 提交于 2020-01-02 07:10:46

问题


The map::erase() method has two overloads to remove a single item:

void erase ( iterator position );
size_type erase ( const key_type& x );

I need to check which version is likely to be faster - my guess would be the first, because the second probably has to call map::find() to look up the iterator?

Can anyone confirm?

Thanks!


回答1:


The first one is amortized constant complexity, the second is logarithmic. It is unlikely that the constant term would be large enough to make the first version slower than the second, but I imagine they must be indistinguishable from each other for very small maps.



来源:https://stackoverflow.com/questions/12078795/stdmaperase-which-overload-is-faster

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!