C++ Hash tables

Started by
3 comments, last by Dark Rain 18 years, 8 months ago
Are there any c++ libraries implementing a hashtable ?
There is nothing that can't be solved. Just people that can't solve it. :)
Advertisement
VC++ has a hash_map class. Probably some other STL implementations do, too.
Some compilers (mingw off the top of my head) support __gnu_cxx::hash_table<> as an extension of the C++ Standard Library.


Right now it depends on your compiler. But I believe hash_map is going to be added to the C++ Standard Library once the C++ Standards Committee finalizes the next language draft.

Good luck.
There is a non-standard std::hash_map or stdext::hash_map (depending on the compiler... yes, 'std' is improper here). There also is the upcoming std::tr1::unordered_map, for which you will have to wait.

Currently, the closest standard container would be a std::map, which offers O(log n) operations.
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
You can use maps, just don't use something like std::map<std::string, mystruct> it's very slow. I use hash_map so I haven't tried it but I suppose you could just create a map using hash of your string as a key and use that to retrieve the result in a fast way. It's just not as convenient as using hash maps directly and you have to write your own hashing functions too. At this point I'd just bite the bullet and use a 3rd party hash_map.

This topic is closed to new replies.

Advertisement