c++資料結構 --unorder_map

來源:互聯網
上載者:User

標籤:his   unsigned   lib   雜湊   程式   ini   closed   compare   字元   

#include <iostream>#include <unordered_map>using namespace std;class Book{private:    string num;    string name;public:    Book() {};    Book(string num,string name) { this ->name = name;this ->num = num;};    string getNum() { return num;};    string getName() { return name;};};int main(){    unordered_map<string,Book>lib;    Book b("001","進階語言程式設計") ;    lib[b.getNum()] = b;    unordered_map<string,Book>::iterator it;    it  = lib.find( *(new string("001")) );    if ( it != lib.end() )        cout << (it ->second).getName();    else        cout << "沒有給元素!";    return 0;}
unsigned int JSHash(const char *str){    unsigned int hash = 1315423911;    while (*str){        hash ^= ((hash << 5) + (*str++) + (hash >> 2));    }    return (hash & 0x7FFFFFFF);}class StrHash{public:    size_t operator()(const string& s) const {        return JSHash(s.c_str());    }};class StrCompare{public:    bool operator()(const string& a,const string& b) const {        return (a==b);    }};
字元雜湊及字串比較函數

note:

1.內部實現為: hasht_table

2.樣本中,已string為key,unorder_map已經為string建立了hash值計算函數,所以無需重寫(貌似是這樣的)

3.(Todo)詳解具體使用方法

c++資料結構 --unorder_map

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.