谁能推荐一个C++ std::map 替换容器?

发布于 2024-07-06 04:41:22 字数 1449 浏览 6 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

盛夏尉蓝 2024-07-13 04:41:22

您可以使用 std::tr1::unordered_map,它已存在于大多数 STL 实现中,并且是 C++0x 标准的一部分。

这是它当前的签名:

template <class Key,
          class T,
          class Hash = std::tr1::hash<Key>,
          class Pred = std::equal_to<Key>,
          class Alloc = std::allocator<std::pair<const Key, T> > >
class unordered_map;

You can use std::tr1::unordered_map, which is already present in most STL implementations, and is part of the C++0x standard.

Here is it's current signature :

template <class Key,
          class T,
          class Hash = std::tr1::hash<Key>,
          class Pred = std::equal_to<Key>,
          class Alloc = std::allocator<std::pair<const Key, T> > >
class unordered_map;
简单气质女生网名 2024-07-13 04:41:22

也许 Google SparseHash 可以帮助您?

Maybe Google SparseHash could help you?

書生途 2024-07-13 04:41:22

请参阅 Loki::AssocVector 和/或 hash_map (大多数 STL 实现都有这个)。

See Loki::AssocVector and/or hash_map (most of STL implementations have this one).

等风来 2024-07-13 04:41:22

如果您的密钥是一种可以快速比较的简单类型,并且您的条目不超过几千个,则只需将密钥对放入 std::vector 中并迭代即可获得更好的性能找到你的价值。

If your key is a simple type that can be very quickly compared and you have no more than a few thousands of entries, you could have better performance by simply putting your pairs in an std::vector and iterating to find your value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文