Questions / wishes hash_map

I know how hashmap works in Java. But I can not fully understand in C ++.

I found some simple guides but no hashfunctions etc.

Is a string hash required?

hash_map<string, string> hm;
hm.insert(make_pair("one", "two"));
hm.insert(make_pair("three", "four"));

how will it work without hash functions for the string? How to add a hash function?

Is there a good tutorial for hash_map?

Thank!

+3
source share
2 answers

hash_map ++; , Visual Studio g++. - ++, Boost.Unordered, TR1, , , ++ 0x. , unordered_map unordered_set, hash_map hash_set, .

, -, hash_map - , std::string, . -, , operator() -, hash_map . :

struct MyCustomHash {
    size_t operator() (const string& str) const {
        /* Terrible hash function... for instructional purposes only! */
        return str.empty()? 0 : str[0];
    }
};

hash_map<string, int, MyCustomHash> myHashMap;

myHashMap MyCustomHash - .

, !

+10

hashmap ? , ++ 0x, std:: unordered_map, - ( ). hashmap -, ( -).

+1

All Articles