unordered_map: which one is faster find() or count()?

前端 未结 2 906
灰色年华
灰色年华 2021-02-02 08:34

What is the fastest way to figure out if an unordered_map container has an item with a specified key?

2条回答
  •  盖世英雄少女心
    2021-02-02 09:23

    They will have about equal performance. You should use the algorithm that best expresses what you are trying to do.

    To elaborate on that, generally count() will be implemented using find(). For example, in libcxx, count() is implemented as return (find(__k) != end());

提交回复
热议问题