• linux下使用hash_map及STL总结


    linux下使用hash_map及STL总结

        linux下使用hash_map及STL总结
        作者: zhdrfirst  时间: 2010-10-21

        出处:http://blog.chinaunix.net/u3/119070/showart_2363418.html

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

        // 文件/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>声明了set和multiset,<map>声明了map和multimap。

        2. 除了四个算法外,所有的算法都在<algorithm>中声明。例外的是accumulate、inner_product、adjacent_difference和partial_sum。这些算法在<numeric>中声明。

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

        4.标准仿函数(比如less<T>)和仿函数适配器(比如not1、bind2nd)在<functional>中声明。
  • 相关阅读:
    13.numpy线性代数和绘图
    12-numpy矩阵
    11-numpy视图与副本
    10-numpy排序搜索
    day12 异常 模块 单例
    day11面向对象 多态 静态方法 (三)
    day 10 面向对象(=)
    day9 面向对象
    day8 文件
    day7 地址 名片管理系统
  • 原文地址:https://www.cnblogs.com/lexus/p/2938243.html
Copyright © 2020-2023  润新知