Sign in to follow this  
BTownTKD

implementational differences between map and hash_map?

Recommended Posts

Hey guys -- I've written a program that records the frequency of words using a map<string, int> What would I need to do to change this to a hash_map using the same data types? I've heard something about writing hash functions and such, but could somebody explain this a little clearer for me? I want to make a simple switch from a map<string, int> to a hash_map<string, int> Thanks in advance!

Share this post


Link to post
Share on other sites
hash_map is a non-standard container. What it would take to change to work with a hash_map depends on what hash_map implementation you've got.

Share this post


Link to post
Share on other sites
MSVC and g++ have incompatible hash_map implementations with their default installations. They don't even take the same number of template arguments. To use the libstdc++ version, you'll need to define a hash functor for std::string. The easy way would be to have it call hash<const char*>. You'll also need to define a functor for equality comparisons. Then you can instantiate it via hash_map<string, int, HashFn, EqFn> where HashFn and EqFn are the hash functor and equality functors. You can find more details at here.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this