什么地图和hashmap在STL之间的区别 [英] what the difference between map and hashmap in STL
本文介绍了什么地图和hashmap在STL之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C ++ STL中,有两个map,map和hashmap。任何人都知道他们的主要区别?
in C++ STL, there are two map, map and hashmap. Anyone know the main difference of them?
推荐答案
地图使用红黑树作为数据结构,在有排序,并且插入/删除是O(log(n))。这些元素需要至少实现运算符<
。
map uses a red-black tree as the data structure, so the elements you put in there are sorted, and insert/delete is O(log(n)). The elements need to implement at least operator<
.
hashmap使用散列,删除是O(1)。元素需要实现至少 operator ==
,您需要一个散列函数。
hashmap uses a hash, so elements are unsorted, insert/delete is O(1). Elements need to implement at least operator==
and you need a hash function.
这篇关于什么地图和hashmap在STL之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文