• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Benjamin

            靜以修身,儉以養(yǎng)德,非澹薄無(wú)以明志,非寧?kù)o無(wú)以致遠(yuǎn)。
            隨筆 - 397, 文章 - 0, 評(píng)論 - 196, 引用 - 0
            數(shù)據(jù)加載中……

            linux平臺(tái)hash_map使用示例

             1 #include <string
             2 #include <iostream> 
             3 #include <ext/hash_map>
             4 using namespace __gnu_cxx; 
             5  
             6 //define the class 
             7 class ClassA{ 
             8 public
             9     ClassA(int a):c_a(a){} 
            10     int getvalue()const { return c_a;} 
            11     void setvalue(int a){c_a;} 
            12 private
            13     int c_a; 
            14 }; 
            15 
            16 //1 define the hash function 
            17 struct hash_A
            18 { 
            19     size_t operator()(const class ClassA & A)const
            20     { 
            21         // return hash<int>(classA.getvalue()); 
            22         return A.getvalue(); 
            23     } 
            24 }; 
            25 
            26 
            27 //2 define the equal function 
            28 struct equal_A
            29 { 
            30     bool operator()(const class ClassA & a1, const class ClassA & a2)const
            31     { 
            32         return a1.getvalue() == a2.getvalue(); 
            33     } 
            34 };
            35 
            36 struct foo
            37 {
            38     int a ;
            39     int b ;
            40     foo(int x,int y):a(x),b(y) {};// ok, 先初始化i,后初始化j
            41     foo(){};
            42 };
            43 int main() 
            44 { 
            45     hash_map<ClassA, foo, hash_A, equal_A> hmap; 
            46     
            47     ClassA a1(12); 
            48     foo t1(122,233);
            49     hmap[a1]=t1; 
            50 
            51     ClassA a2(198877);
            52     foo t2(198877,6698);
            53     hmap[a2]=t2; 
            54 
            55     std::cout<<hmap[a1].a<<std::endl; 
            56     std::cout<<hmap[a2].b<<std::endl; 
            57     
            58     hash_map<ClassA, foo, hash_A, equal_A>::iterator it = hmap.find(12);
            59     if(it != hmap.end())
            60     {
            61         std::cout<<it->second.a<<std::endl;
            62    }
            63 
            64         foo t3(43,67);
            65     hmap.insert(pair<int, foo>(78,t3));
            66     return 0; 
            67 } 
            68 
            如果鍵值是指針可這樣寫:hash_map<int,classA*>,key是int,classA*是value的類型,和vc中使用的情況一樣   

            posted on 2015-01-02 15:51 Benjamin 閱讀(885) 評(píng)論(0)  編輯 收藏 引用 所屬分類: linux

            99久久久精品免费观看国产| 91超碰碰碰碰久久久久久综合| 久久精品国产免费观看| 99久久无色码中文字幕人妻| 久久综合九色综合97_久久久| 久久影视综合亚洲| 欧洲精品久久久av无码电影| 久久国产精品视频| 国产精品99精品久久免费| 热综合一本伊人久久精品| 国产人久久人人人人爽| 久久久久久国产精品无码下载| 欧美伊香蕉久久综合类网站| 777午夜精品久久av蜜臀| 久久久艹| 久久人妻少妇嫩草AV无码蜜桃| 久久狠狠色狠狠色综合| 无码人妻精品一区二区三区久久| 久久久久亚洲AV无码专区桃色 | 91久久成人免费| 久久精品一本到99热免费| 亚洲色欲久久久综合网| 色青青草原桃花久久综合| 久久久久亚洲精品无码网址| 一级做a爰片久久毛片人呢| MM131亚洲国产美女久久| 午夜精品久久久久久久| 伊人久久大香线焦AV综合影院| 亚洲欧美精品一区久久中文字幕| 久久久精品久久久久久| 久久强奷乱码老熟女网站| 亚洲?V乱码久久精品蜜桃 | 亚洲va久久久噜噜噜久久狠狠| 久久人人添人人爽添人人片牛牛| 思思久久精品在热线热| 欧美日韩精品久久免费| 久久久久久伊人高潮影院| 熟妇人妻久久中文字幕| 久久久久一区二区三区| 99热都是精品久久久久久| 精品久久久久久无码免费|