[ACCEPTED]-Hashtable in C++?-complexity-theory

Accepted answer
Score: 81

If you're using C++11, you have access to 7 the <unordered_map> and <unordered_set> headers. These provide classes 6 std::unordered_map and std::unordered_set.

If you're using C++03 with TR1, you 5 have access to the classes std::tr1::unordered_map and std::tr1::unordered_set, using 4 the same headers (unless you're using GCC, in 3 which case the headers are <tr1/unordered_map> and <tr1/unordered_set> instead).

In 2 all cases, there are corresponding unordered_multimap and 1 unordered_multiset types too.

Score: 16

If you don't already have unordered_map 1 or unordered_set, they are part of boost.
Here's the documentation for both.

Score: 3

There is a hash_map object as many here have mentioned, but 3 it is not part of the stl. It is a SGI 2 extension, so if you were looking for something 1 in the STL, I think you are out of luck.

Score: 2

Visual Studio has the class stdext::hash_map in the header 1 <hash_map>, and gcc has the class __gnu_cxx::hash_map in the same header.

Score: 2

std::tr1::unordered_map, in <unordered_map>

if you don't 2 have tr1, get boost, and use boost::unordered_map 1 in <boost/unordered_map.hpp>

Score: 1

See std::hash_map from SGI.

This is included in the STLPort distribution 1 as well.

Score: 1

hash_map is also supported in GNU's libstdc++.

Dinkumware 3 also supports this, which means that lots of implementations 2 will have a hash_map (I think even Visual 1 C++ delivers with Dinkumware).

Score: 1

If you have the TR1 extensions available 5 for yor compiler, use those. If not, boost.org 4 has a version that's quite similar except 3 for the std:: namespace. In that case, put 2 in a using-declaration so you can switch 1 to std:: later.

More Related questions