map和hash_map在C ++ [英] map vs. hash_map in C++

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

问题描述

我在C ++中有一个问题, hash_map map 我理解 map 是在STL,但 hash_map 不是一个标准。

I have a question with hash_map and map in C++. I understand that map is in STL, but hash_map is not a standard. What's the difference between the two?

推荐答案

它们是以非常不同的方式实现的。

They are implemented in very different ways.

hash_map (在TR1和Boost中使用 unordered_map ;使用那些)

hash_map (unordered_map in TR1 and Boost; use those instead) use a hash table where the key is hashed to a slot in the table and the value is stored in a list tied to that key.

map 实现为平衡的二叉搜索树(通常是红/黑树)。

map is implemented as a balanced binary search tree (usually a red/black tree).

unordered_map 用于访问集合的已知元素的更好的性能,但是 map 将具有另外有用的特征(例如,以排序顺序存储,这允许从开始到完成的遍历)。 unordered_map 在插入和删除时比映射更快。

An unordered_map should give slightly better performance for accessing known elements of the collection, but a map will have additional useful characteristics (e.g. it is stored in sorted order, which allows traversal from start to finish). unordered_map will be faster on insert and delete than a map.

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

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