C ++中的Hashtable? [英] Hashtable in C++?

查看:155
本文介绍了C ++中的Hashtable?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用C ++ stdlib地图,每当我需要存储一些特定类型的值(一个键值 - 例如字符串或其他对象)相关联的数据。 stdlib映射实现基于树,它提供比标准数组或stdlib向量更好的性能(O(log n))。

I usually use C++ stdlib map whenever I need to store some data associated with a specific type of value (a key value - e.g. a string or other object). The stdlib map implementation is based on trees which provides better performance (O(log n)) than the standard array or stdlib vector.

我的问题是,你知道任何提供更好性能(O(1))的C ++标准散列表实现?

My questions is, do you know of any C++ "standard" hashtable implementation that provides even better performance (O(1))? Something similar to what is available in the Hashtable class from the Java API.

推荐答案

如果你使用的是C ++ 11,您可以访问< unordered_map> < unordered_set> 头。这些提供类 std :: unordered_map std :: unordered_set

If you're using C++11, you have access to the <unordered_map> and <unordered_set> headers. These provide classes std::unordered_map and std::unordered_set.

如果你使用TR1的C ++ 03,你可以访问类 std :: tr1 :: unordered_map std :: tr1 :: unordered_set ,使用相同的头(除非你使用GCC,在这种情况下头是< tr1 / unordered_map>

If you're using C++03 with TR1, you have access to the classes std::tr1::unordered_map and std::tr1::unordered_set, using the same headers (unless you're using GCC, in which case the headers are <tr1/unordered_map> and <tr1/unordered_set> instead).

在所有情况下,都有相应的<$ c $

In all cases, there are corresponding unordered_multimap and unordered_multiset types too.

这篇关于C ++中的Hashtable?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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