std :: map :: erase() - 哪个重载更快? [英] std::map::erase() - which overload is faster?

查看:127
本文介绍了std :: map :: erase() - 哪个重载更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

map :: erase()方法有两个重载来删除单个项目:

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

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

我需要检查哪个版本可能会更快 - 我的猜测是第一个,因为第二个可能要调用map :: find()来查找迭代器?

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?

任何人都可以确认?

谢谢!

推荐答案

第一个是摊销常数复杂度,第二个是对数。不可能的是,固定的术语将足够大,以使第一版本比第二版更慢,但是我认为它们对于非常小的地图必须彼此无法区分。

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.

这篇关于std :: map :: erase() - 哪个重载更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆