linux下使用hash_map及STL总结

来源:互联网 发布:数据库日志恢复 编辑:程序博客网 时间:2024/04/27 23:39
2010-10-21 18:57:14

hash_map不是C++标准库的一部分,但因其重要性很多库(sgi stlboost)实现了hash_map,包括g++编译器所带的头文件也包含了hash_map的实现代码(其实现为sgi stl的版本),其在include/ext目录下,该目录还包含了hash_setrope等的实现。

// 文件/usr/include/c++/4.4.0/ext/hash_map

_GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
 65 
 66 using std::equal_to;
 67 using std::allocator;
 68 using std::pair;
 69 using std::_Select1st;
 70 
 71 /**
 72 * This is an SGI extension.
 73 * @ingroup SGIextensions
 74 * @doctodo
 75 */

 76 template<class _Key, class _Tp, class _HashFn = hash<_Key>,
 77 class _EqualKey = equal_to<_Key>, class _Alloc = allocator<_Tp> >
 78 class hash_map


首先从上述头文件开始的部分可以发现,hash_map定义在__gnu_cxx命名空间中,故你必须在使用时限定名字空间__gnu_cxx::hash_map,或者使用using关键字,如下例:

#include <ext/hash_map>
using namespace __gnu_cxx;

int main()
{
    hash_map<int, string> hm;
    /* 其它使用hash_map的代码 */
}


STL其它头文件信息:

1.几乎所有的容器都在同名的头文件里,比如,vector<vector>中声明,list<list>中声明等。例外的是<set><map><set>声明了setmultiset<map>声明了mapmultimap

2. 除了四个算法外,所有的算法都在<algorithm>中声明。例外的是accumulateinner_productadjacent_differencepartial_sum。这些算法在<numeric>中声明。

3.特殊的迭代器,包括istream_iteratorsistreambuf_iterators,在<iterator>中声明。

4.标准仿函数(比如less<T>)和仿函数适配器(比如not1bind2nd)在<functional>中声明。

原创粉丝点击