Sunday, September 19, 2010

Confusing of “map” (data structure)

According to wikipedia, a map is an associative array, and “an associative array (also associative container, map, mapping, dictionary, finite map, and in query-processing an index or index file) is an abstract data type composed of a collection of unique keys and a collection of values, where each key is associated with one value (or set of values).” we could simply see a map as a colletion of <key, value > pairs. This definition does not define the detail of its implementation.

However, in C++ STL, map is a sorted associative array, and is implemented by red-black tree. Therefore, more precisely, in C++, a map is a container that implemented by red-black tree, and nodes are pairs.

In java, a map is an interface that “maps keys to values.” The abstractmap class implemented map interface. Under the “abstractmap” class, there are hashmap and treemap. Obviously, a hashmap is implemented by hash table, and a treemap is implemented by red-black tree.

Therefore, when we talk about “map”, we have to know the context. However, saying “a hash table” is a map is always not right.

No comments:

Post a Comment