我爱编程

unordered_map

2018-08-09  本文已影响0人  影醉阏轩窗

百度都是关于unorder_mapmap的差别等,主要讲效率什么的,而我只想快速的使用unorder_map而已。

简要说明unorder_map

  1. 效率高
  2. 内部使用harsh原理构造
  3. 多用在关联性比较高的数据结构中
  4. 多用在查找、对比等算法中......

函数简介

使用类似python的字典,也就是key和value对应关系。

unordered_map<Key,T>

遍历unorder_map中的key和value:

   unordered_map<key,T>::iterator it;
    (*it).first;        //the key value
    (*it).second   //the mapped value
    for(unordered_map<key,T>::iterator iter=mp.begin();iter!=mp.end();iter++)
          cout<<"key value is"<<iter->first<<" the mapped value is "<< iter->second;

    也可以这样:
    for(auto& v : mp)
        print v.first and v.second


    若有unordered_map<int, int> mp;查找x是否在map中
    //方法1:  若存在  mp.find(x)!=mp.end()
    //方法2:  若存在  mp.count(x)!=0



Hash policy

后面两个暂时还不懂什么意思,之后用到再进行总结。

参考链接

这几次写文章都忘记写参考链接,非常抱歉!!!

一个简单介绍文章

官网

上一篇 下一篇

猜你喜欢

热点阅读