unordered_map:哪种更快的find()或count()? [英] unordered_map: which one is faster find() or count()?
本文介绍了unordered_map:哪种更快的find()或count()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
找出 unordered_map
容器是否具有带有指定键的项目的最快方法是什么?
What is the fastest way to figure out if an unordered_map
container has an item with a specified key?
推荐答案
它们的性能差不多。您应该使用最能表达您要执行的操作的算法。
They will have about equal performance. You should use the algorithm that best expresses what you are trying to do.
要对此进行详细说明,通常 count()
将使用 find()
实现。例如,在 libcxx 中, count()
被实现为返回(find(__ k)!= end());
To elaborate on that, generally count()
will be implemented using find()
. For example, in libcxx, count()
is implemented as return (find(__k) != end());
这篇关于unordered_map:哪种更快的find()或count()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文