C++ map使用(基于hashtable)

C++ map使用(基于hashtable)

实际上基于hashtable的map有两种一种是hash_map,unordered_map,但是最好使用后者,原因如下[1]

  • 因为标准化的推进,unordered_map原来属于boost分支和std::tr1中,而hash_map属于非标准容器。
  • 另外,使用之后,感觉速度和hash_map差不多,但是支持string做key,也可以使用复杂的对象作为key。
  • 速度上unordered_map>hash_map>map

 具体的使用方式可以参考[3],因为需要使用hash函数,除了使用默认的hash函数之外,也可以使用自定义的hash函数

参考文献:

[1] http://my.huhoo.net/archives/2008/10/unordered_maphash_map.html

[2] http://www.cnblogs.com/luxiaoxun/archive/2012/09/02/2667782.html 一个hashmap的实现

[3] http://www.th7.cn/Program/cp/2011/07/29/35870.shtml

你可能感兴趣的:(Hashtable)