任何人都可以推荐一个C++ std :: map替换容器吗?

Rob*_*uld 10 c++ stdmap

地图非常适合轻松完成任务,但它们是内存耗尽并且存在缓存问题.当你在关键循环中有一张可能不好的地图时.

所以我想知道是否有人可以推荐另一个具有相同API但是使用的容器让我们说一个向量或哈希实现而不是树实现.我的目标是交换容器,而不必重写依赖于地图的所有用户代码.

更新:性能明智,最好的解决方案是在std :: vector上测试地图外观

Luc*_*lle 11

您可以使用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;
Run Code Online (Sandbox Code Playgroud)


Igo*_*nov 6

也许Google SparseHash可以帮到你?


yrp*_*yrp 4

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