gpt4 book ai didi

c++ - std::unordered_map 是否仍然需要散列整数才能得到值?

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:50:36 25 4
gpt4 key购买 nike

我想知道是否std::unordered_map< int, float >仍然必须对给定的整数进行哈希处理才能得到该值,或者直接使用它。我需要每秒多次快速执行此操作,如 std::hash<int>不能保证是身份函数,我将如何重新定义它? (显然不使用 STL 并编写我自己的容器是可能的,但我怀疑我编写的容器是否会更有效率(可能慢得多,慢得多))。谢谢!

最佳答案

I would like to know whether std::unordered_map< int, float > still has to hash the given integer

是的。

I need to perform this operation very fast many times

您是否完成了您的项目并见证了这是它的瓶颈?如果不是,请当心,因为您可能最终成为过早优化的受害者!

how would I go about redefining it?

然后您必须编写自己的代码。示例:C++ unordered_map using a custom class type as the key , 你会在哪里使用 struct Key { int value; }; .

关于c++ - std::unordered_map<int,float> 是否仍然需要散列整数才能得到值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46533991/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com