implementational differences between map and hash_map?

Started by
2 comments, last by SiCrane 18 years, 1 month ago
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!
Deep Blue Wave - Brian's Dev Blog.
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.
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++.
Deep Blue Wave - Brian's Dev Blog.
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.

This topic is closed to new replies.

Advertisement