简体   繁体   English

为什么C ++标准库不包含哈希表实现?

[英]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 table 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. 我正在阅读我的教科书Data Structures and Algorithms: By Mark Allen Weiss ,它说标准库不包含集合或映射的哈希表实现,而是编译器可以提供具有相同成员函数的hash_set和hash_map和地图类。 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? 这本书于2006年出版,自从将这些实现添加到标准库以来,是否有任何C ++版本?

What you're looking for are called std::unordered_set/map . 您正在寻找的是名为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). 这些是C ++ 11的一部分, C ++ 11是C ++标准的下一个版本(将在几个月后完成)。 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. 它们也在2005年的技术报告1中提供,这是第一个标准和下一个标准库之间的C ++标准库的附加列表。 In TR1, they were in the std::tr1 namespace. 在TR1中,它们位于std::tr1命名空间中。

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). Boost实际上提供了TR1实现 (尽管你不应该使用std::tr1::shared_ptr版本,因为C ++ 11中的常规boost::shared_ptrstd::shared_ptr要好得多)。

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. 如果我记得,最初在C ++ 98中引入散列表的原因只是缺乏C ++标准委员会的时间。 They basically had a cut-off date in order to ship the thing, and hash tables didn't make it. 他们基本上有一个截止日期,以便运送东西,哈希表没有成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM