Tony The Lion
Tony The Lion

Reputation: 63200

difference in implementation of map and dictionary

I know what the difference is in terms of where a map or where a dictionary is used, but what I wondered is why a Dictionary<TKey, TValue> in .NET supposedly uses, from what I've read here, a linked list under the covers and I know that a std::map<K,T> (C++) is implemented as a red-black tree.

Why aren't they the same under the covers, is there some difference in performance, (which I know that a C++ data structure is optimized for) or why would the .NET dictionary actually be a linked list under the covers and the C++ std::map then a red-black tree, which to my knowledge are completely different data structures, used for entirely different purposes mostly.

Perhaps these two things serve a different purpose and maybe I just don't know.

Can anybody clarify?

Upvotes: 2

Views: 806

Answers (1)

ildjarn
ildjarn

Reputation: 62975

Dictionary<> is a hash table, akin to std::unordered_map<>.

SortedDictionary<> is a red-black tree, akin to std::map<>.

Upvotes: 3

Related Questions