diff options
author | Georg Brandl <georg@python.org> | 2012-03-14 06:50:17 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2012-03-14 06:50:17 (GMT) |
commit | b20a019d467daad5a6e2856a36fca4d90904f969 (patch) | |
tree | 3dbe8a87ddf947686f576d0efbb0a6ddb805089b /Doc | |
parent | 1725feabd0755b55bb228f8d7cc8c447cdaef988 (diff) | |
download | cpython-b20a019d467daad5a6e2856a36fca4d90904f969.zip cpython-b20a019d467daad5a6e2856a36fca4d90904f969.tar.gz cpython-b20a019d467daad5a6e2856a36fca4d90904f969.tar.bz2 |
Closes #14298: update section about dict implementation.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/faq/design.rst | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Doc/faq/design.rst b/Doc/faq/design.rst index 1521f6c..5441fd4 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? |