STL源码剖析(五)【hash_set、hash_map】

hash_set

与set区别及联系

  1. 与set大同小异,set以RB-tree作为其底层,而hash_set以hash table作为其底层
  2. 两者都是借由其底层操作完成我们所看到的那些操作
  3. 二者最大的不同在于set的底层RB-tree有自动排序功能,所以反映在set中也含有自动排序功能,而hashtable并无自动排序功能,自然hash_set也无自动排序功能

运用hash_set

#include <hash_set>  //c++11中使用  #include <unordered_set>
//...
hash_set<int> Set;

hash_multiset

与hash_set一致,不过插入时采用insert_equal,允许重复键值,而hash_set采用insert_unique

注意:C++11 中无hash_set,使用时使用unordered_set

hash_map

与map区别及联系

  1. 与map大同小异,map以RB-tree作为其底层,而hash_map以hash table作为其底层
  2. 两者都是借由其底层操作完成我们所看到的那些操作
  3. 二者最大的不同在于map的底层RB-tree有自动排序功能,所以反映在map中也含有自动排序功能,而hashtable并无自动排序功能,自然hash_map也无自动排序功能

运用hash_map

#include <hash_map>  //c++11中使用  #include <unordered_map>
//...
hash_map<int> map;

hash_multimap

与hash_set一致,不过插入时采用insert_equal,允许重复键值,而hash_set采用insert_unique

注意:C++11 中无hash_map,使用时使用unordered_map

总结一下,最近一段时间感觉博客写的有点不太尽人意,可能是书上重要的东西有点多,导致博客大都是书上的内容,接下来一段时间的学习会重点放在linux与算法中,所以这本书的后续内容可能会穿插在其中,等看完本书后会有个比较详细的一个总结,所以,就这样吧!Fighting!!!

最后欢迎大家来我的小房子踩踩二笙的小房子

猜你喜欢

转载自blog.csdn.net/qq_38790716/article/details/84719271