Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a standard C++ Hash Container?

I have a variety of textbooks that note that there wasn't a hash container originally incorporated into the STL, but most also say that most standard library implementations do have some form of hash container since it was a known shortfall.

These books aren't necessarily as up to date as possible, and I got a little confused about what was really "standard" when googling, so:

At this point in time, do most standard library implementations provide a fairly consistent hash container, and if so, is it considered a part of the STL?

What's the "standard" header for this container? (I'm guessing it's #include <hash>, but just in case!).

Is there a hash set and hash map separately defined for use?

like image 924
John Humphreys Avatar asked Nov 30 '22 07:11

John Humphreys


2 Answers

The new standard hash map container is called unordered_map. You can include it in your files by #include <unordered_map>. It is part of the now-approved standard C++11.

Before C++11, you had various things like hash_map which were (widely?) supported by some vendors so you could use them, but if you did, your code wasn't really portable because hash_map wasn't part of the standard. hash_map and all the other vendor-specific versions of a hash table structure shouldn't be used now.

like image 66
Seth Carnegie Avatar answered Dec 05 '22 06:12

Seth Carnegie


See C++11 types:

  • unordered_map
  • unordered_set
  • unordered_multimap
  • unordered_multiset
like image 34
Didier Trosset Avatar answered Dec 05 '22 07:12

Didier Trosset