Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is hash_map part of the STL?

Tags:

c++

hashmap

stl

Quick question...Is hash_map part of the STL?

like image 438
Jake Avatar asked May 06 '11 08:05

Jake


People also ask

Is HashMap same as map in C++?

Hashmap uses a hash table where the key is hashed to a slot in the table and the value is stored in a list tied to that key. The map is implemented as the balanced BST (binary search tree). This is the key difference between them.

Is unordered_map and HashMap same?

Yes, HashMap in java and unordered_map in c++ stl are more or less the same… you can store pointers in java too(Don't forget, in java, everything you deal with is a reference)…

Is hashing and mapping same?

A map cannot contain duplicate keys; each key can map to at most one value. HashMap is a Hash table based implementation of the Map interface. HashMap provides all of the optional map operations, and permits null values and the null key.

Is Hashtable a map?

is it a map or a hashtable? Yes. The static, compile time type of the reference is Map .


2 Answers

The STL has hash_map, but the C++ Standard Library does not.

Due to a common misconception, you may think of the C++ Standard Library as "the STL", or of parts of your toolchain's implementation of the C++ Standard Library as "an STL implementation".

It is not.

It is also a great shame that both MSVC++ and GCC (which implement hash_map as a compiler-specific extension), place it in the std namespace, which is not only highly misleading, but also illegal per the standard. *sigh*

C++11 has introduced std::unordered_map, which is not dissimilar.

like image 64
Lightness Races in Orbit Avatar answered Sep 21 '22 15:09

Lightness Races in Orbit


Quoting Wikipedia (emphasis added):

From the STL page:

The Standard Template Library (STL) is a software library partially included in the C++ Standard Library.

...and then from the hash_map page

In the C++ programming language, hash_map is the name of a hashed associative container in the Standard Template Library. It is provided by several implementors, such as the GNU C++ compiler and Microsoft's Visual C++. It is not part of the C++ Standard Library, but the C++ Technical Report 1 contains the very similar container unordered_map, which will be included in the upcoming C++0x standard.

So in short,

  • YES it's part of the STL.
  • But it IS NOT part of the standard library.
  • But it is supported by several very popular implementations.
like image 45
razlebe Avatar answered Sep 20 '22 15:09

razlebe