Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the STL contain a hashtable? [duplicate]

Tags:

Possible Duplicates:
Hashtable in C++?
can anybody offer a simple hash_map example in C++?

Does the STL contain an implementation of a hashtable?

If so, can you provide a brief example of how to use it?

like image 262
Mithrax Avatar asked Feb 03 '10 15:02

Mithrax


People also ask

Do hash tables have duplicates?

Hashtable FeaturesIt does not accept duplicate keys. It stores key-value pairs in hash table data structure which internally maintains an array of list. Each list may be referred as a bucket. In case of collisions, pairs are stored in this list.

Is Hashmap part of STL?

Yes, hash_map is part of the STL. However, it is not part of C++03's standard library.

How the hash map is implemented in STL?

Internally unordered_map is implemented using Hash Table, the key provided to map are hashed into indices of a hash table that is why the performance of data structure depends on hash function a lot but on an average, the cost of search, insert and delete from the hash table is O(1).


2 Answers

Current standard implementation doesn't, STL::TR1 does, see Unordered Map.

Most modern compilers have a TR1 implementation, if that fails, you may always use the Boost TR1 implementation.

  • MSVC has it for VS2008 via service pack 1
  • GCC has it shipped with 4.x, but you can make it work with 3.4.x too AFAIR

Usage is almost the same as with a std::map.

like image 191
Kornel Kisielewicz Avatar answered Dec 22 '22 00:12

Kornel Kisielewicz


While not officially part of the STL standard, hash_map and hash_set are commonly used to improve searching times......

http://msdn.microsoft.com/en-us/library/0d462wfh%28VS.80%29.aspx

So, long story short--no .

like image 27
bdd Avatar answered Dec 22 '22 00:12

bdd