linux下使用hash_map及STL總結

來源:互聯網
上載者:User

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>中聲明。

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.