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;
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.
发布评论
评论(4)
您可以使用 std::tr1::unordered_map,它已存在于大多数 STL 实现中,并且是 C++0x 标准的一部分。
这是它当前的签名:
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 :
也许 Google SparseHash 可以帮助您?
Maybe Google SparseHash could help you?
请参阅 Loki::AssocVector 和/或 hash_map (大多数 STL 实现都有这个)。
See Loki::AssocVector and/or hash_map (most of STL implementations have this one).
如果您的密钥是一种可以快速比较的简单类型,并且您的条目不超过几千个,则只需将密钥对放入
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.