4

What is the data structure used for following line of code in C++?

map <char, int> dict; 

Is it a hash table?

0

4 Answers 4

6

std::unordered_map uses hashing to store its objects.

Sign up to request clarification or add additional context in comments.

Comments

4

The standard does not impose any specific implementation on std::map. It only gives the required operations and their complexity. Those factors lead to the actual implementation choice which is usually a Red-black Tree.

The chapter listing the requirements for std::map is 23.2.4 Associative Containers in C++11.

Comments

0

It is usually implemented with a self-balancing BST. Implementation is actually compiler specific.

std::map<char, int> dict; 

A char is the key while an int is the corresponding value.

1 Comment

I don't think there is any requirement for it to be Red-Black tree implementation. It could be anything under the hood if the semantics are followed.
0

It uses Red-Black Tree to organize keys in order.

That's why you can iterate it in ascending order, and the key object has to have operator< overloaded.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.