diff options
author | Georg Brandl <georg@python.org> | 2012-03-17 16:58:12 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2012-03-17 16:58:12 +0100 |
commit | ffd4830f6ab0942a463772a01a91f051bfa2d376 (patch) | |
tree | 14d5f982ed3d51197f0dd69370d3f6002aec8e1e /Doc/faq/design.rst | |
parent | 206a0cc1b0f2545eef212be6210b4bf7008815ba (diff) | |
parent | 5d6d9423be73e8c6f3f18fa3e006573fc5836236 (diff) | |
download | cpython-ffd4830f6ab0942a463772a01a91f051bfa2d376.tar.gz |
merge with 3.2
Diffstat (limited to 'Doc/faq/design.rst')
-rw-r--r-- | Doc/faq/design.rst | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/Doc/faq/design.rst b/Doc/faq/design.rst index 87cc942f31..43ec692564 100644 --- a/Doc/faq/design.rst +++ b/Doc/faq/design.rst @@ -526,14 +526,16 @@ far) under most circumstances, and the implementation is simpler. Dictionaries work by computing a hash code for each key stored in the dictionary using the :func:`hash` built-in function. The hash code varies widely depending -on the key; for example, "Python" hashes to -539294296 while "python", a string -that differs by a single bit, hashes to 1142331976. The hash code is then used -to calculate a location in an internal array where the value will be stored. -Assuming that you're storing keys that all have different hash values, this -means that dictionaries take constant time -- O(1), in computer science notation --- to retrieve a key. It also means that no sorted order of the keys is -maintained, and traversing the array as the ``.keys()`` and ``.items()`` do will -output the dictionary's content in some arbitrary jumbled order. +on the key and a per-process seed; for example, "Python" could hash to +-539294296 while "python", a string that differs by a single bit, could hash +to 1142331976. The hash code is then used to calculate a location in an +internal array where the value will be stored. Assuming that you're storing +keys that all have different hash values, this means that dictionaries take +constant time -- O(1), in computer science notation -- to retrieve a key. It +also means that no sorted order of the keys is maintained, and traversing the +array as the ``.keys()`` and ``.items()`` do will output the dictionary's +content in some arbitrary jumbled order that can change with every invocation of +a program. Why must dictionary keys be immutable? @@ -645,7 +647,7 @@ construction of large programs. Python 2.6 adds an :mod:`abc` module that lets you define Abstract Base Classes (ABCs). You can then use :func:`isinstance` and :func:`issubclass` to check whether an instance or a class implements a particular ABC. The -:mod:`collections` module defines a set of useful ABCs such as +:mod:`collections.abc` module defines a set of useful ABCs such as :class:`Iterable`, :class:`Container`, and :class:`MutableMapping`. For Python, many of the advantages of interface specifications can be obtained |