XOR
XOR

Reputation: 314

map (vs) unordered_map with pair as key

This produces compiler error

unordered_map<pair<int,int>,int> umap;

I understand that a hash function must be provided for it to work.

But

map<pair<int,int>,int> omap;

works perfectly without any hash function.

Why is that so?

Upvotes: 1

Views: 633

Answers (1)

mascoj
mascoj

Reputation: 1329

std::map does not use a hash function. Rather, its "keys are sorted by using the comparison function..." where "search, removal, and insertion operations have logarithmic complexity.". Lookup is done by traversing a search tree rather than via hashing.

Upvotes: 3

Related Questions