Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dictionary/HashTable Object in C++?

Tags:

c++

dictionary

I'm looking for a HashTable or Dictionary implementation in C++ that has similar functionality to the one in C#? Does the STL contain an object like this and how would I use it?

like image 840
cam Avatar asked Apr 27 '10 12:04

cam


People also ask

What is dictionary and Hashtable?

A dictionary is a data structure that maps keys to values. A hash table is a data structure that maps keys to values by taking the hash value of the key (by applying some hash function to it) and mapping that to a bucket where one or more values are stored.

Is Hashtable and dictionary the same?

Hashtable is a loosely typed (non-generic) collection, this means it stores key-value pairs of any data types. Dictionary is a generic collection. So it can store key-value pairs of specific data types.

Is dictionary a Hashmap or Hashtable?

Dictionaries are often also called maps, hashmaps, lookup tables, or associative arrays. They allow the efficient lookup, insertion, and deletion of any object associated with a given key.


2 Answers

Actually, to be exactly the same as .NET's Dictionary/Hashtable, what you want is hash_map or unordered_map (std::map is implemented as a binary tree), hash_map is an extension to the SC++L. Most compilers that I know of come with hash_map, though, and boost obviously has unordered_map until C++0x is available in all compilers, so you should just be able to use it without trouble.

like image 179
Dean Harding Avatar answered Oct 09 '22 02:10

Dean Harding


STL has std::map    

like image 29
spoulson Avatar answered Oct 09 '22 02:10

spoulson