• Advertisement
Sign in to follow this  

implementational differences between map and hash_map?

This topic is 4368 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
I believe it's from the same makers as the STL (SGI?).

Right now I'm using VC++ 2005, but I'll ultimately be submitting my final program to a machine that uses g++.

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
Sign in to follow this  

  • Advertisement