查了好多资料,发现还是不全,干脆自己整理吧,至少保证在我的做法正确的,以免误导读者,也是给自己做个记录吧!
大家都知道c++ stl中的map是用红黑树实现的,而tr1中实现了hash结构的map 为了不定名冲突被叫做了unordered_map,,
上面就给大家简略应用下这一结构,如果大家的结构在百万规模级就应该考虑应用该结构了。
#include <iostream> #include <string> #include <algorithm> #include <unordered_map> using namespace std; void print(std::pair<int,std::string> it) { cout << it.first << "-> " << it.second << endl; } void print2(std::pair<string,std::string> it) { cout << it.first << "-> " << it.second << endl; } int main(int argc, char* argv[]) { typedef std::tr1::unordered_map<int,string> hash_map; hash_map hm; hm.insert(std::pair<int,std::string>(0,"Hello")); hm[1] = "World"; for_each(hm.begin(),hm.end(),print); std::tr1::unordered_map<string,string> hashcode_string; hashcode_string.insert(std::pair<string,std::string>("opensss","release")); hashcode_string["opensde"] = "ssss"; for_each(hashcode_string.begin(),hashcode_string.end(),print2); system("pause"); return 0; }
文章结束给大家分享下程序员的一些笑话语录: IBM和波音777
波音777是有史以来第一架完全在电脑虚拟现实中设计制造的飞机,所用的设备完全由IBM公司所提供。试飞前,波音公司的总裁非常热情的邀请IBM的技术主管去参加试飞,可那位主管却说道:“啊,非常荣幸,可惜那天是我妻子的生日,So..”..
波音公司的总载一听就生气了:“胆小鬼,我还没告诉你试飞的日期呢!”
---------------------------------
原创文章 By
置顶和结构
---------------------------------