Why does the Standard Library for C++ not contain hash table implementations?
I was reading over my text book Data Structures and Algorithms: By Mark Allen Weiss
and it says that the standard library does not contain hash 开发者_如何学JAVAtable implementations of a set or map, but rather compilers can provide hash_set and hash_map with same member functions of the set and map class. Why not just include hash implementations in the standard library? The book was published in 2006, have there been any revisions of C++ since to add these implementations to the standard library?
What you're looking for are called std::unordered_set/map
. These are part of C++11, the next version of the C++ standard (due to be finalized in a few months). They were also made available in Technical Report 1 in 2005, which was a list of additions to the C++ standard library between the first standard and the next one. In TR1, they were in the std::tr1
namespace.
Boost actually ships an implementation of TR1 (though you shouldn't use the std::tr1::shared_ptr
version, as the regular boost::shared_ptr
and std::shared_ptr
in C++11 are much, much better).
If I recall, the reason why hash tables were not initially introduced in C++98 was simply a lack of time for the C++ standards committee. They basically had a cut-off date in order to ship the thing, and hash tables didn't make it.
精彩评论