What is the difference between a map and a diction

2019-01-20 21:51发布

I know a map is a data structure that maps keys to values. Isn't a dictionary the same? What is the difference between a map and a dictionary1?


1. I am not asking for how they are defined in language X or Y (which seems to be what generally people are asking here on SO), I want to know what is their difference in theory.

10条回答
贪生不怕死
2楼-- · 2019-01-20 22:30

These are two different terms for the same concept.
Hashtable and HashMap also refer to the same concept.

查看更多
女痞
3楼-- · 2019-01-20 22:31

One is an older term for the other. Typically the term "dictionary" was used before the mathematical term "map" took hold. Also, dictionaries tend to have a key type of string, but that's not 100% true everywhere.

查看更多
Root(大扎)
4楼-- · 2019-01-20 22:31

Typically I assume that a map is backed by a hash table; it connotes an unordered store. Dictionaries connote an ordered store.

There is a tree-based dictionary called a Trie.

In Lisp, it might look like this:

(a (n (d t)) n d )

Which encapsulates the words:

  • a
  • and
  • ant
  • an
  • ad

The traversal from the top to the leaf yields a word.

查看更多
一纸荒年 Trace。
5楼-- · 2019-01-20 22:32

Other terms for this concept that are fairly common: associative array and hash.

查看更多
淡お忘
6楼-- · 2019-01-20 22:39

so on a purely theoretical level.

A Dictionary is a value that can be used to locate a Linked Value. A Map is a Value that provides instructions on how to locate another values

all collections that allow non linear access (ie only get first or get last) are a Map, as even a simple Array has an index that maps to the correct value. So while a Dictionary is a Type of map, maps are a much broader range of possible function.

In Practice a its usually the mapping function that defines the name, so a HashMap is a mapped data structure that uses a hashing algorithm to link the key to the value, where as a Dictionary doesn't specify how the keys are linked to a value so could be stored via a linked list, tree or any other algorithm. from the usage end you usually don't care what the algorithm only that they work so you use a generic dictionary and only shift to one of the other structures only when you need to enfore the type of algorithm

查看更多
Ridiculous、
7楼-- · 2019-01-20 22:40

Yes, they are the same, you may add "Associative Array" to the mix.

using Hashtable or a Hash ofter refers to the implementation.

查看更多
登录 后发表回答