[New-bugs-announce] [issue20674] Update comments in dictobject.c
Raymond Hettinger
report at bugs.python.org
Tue Feb 18 18:33:15 CET 2014
New submission from Raymond Hettinger:
The hash function comments in Objects/dictobject.c no longer match the implementation:
"""
/*
Major subtleties ahead: Most hash schemes depend on having a "good" hash
function, in the sense of simulating randomness. Python doesn't: its most
important hash functions (for strings and ints) are very regular in common
cases:
>>> map(hash, (0, 1, 2, 3))
[0, 1, 2, 3]
>>> map(hash, ("namea", "nameb", "namec", "named"))
[-1658398457, -1658398460, -1658398459, -1658398462]
>>>
This isn't necessarily bad! To the contrary, in a table of size 2**i, taking
the low-order i bits as the initial table index is extremely fast, and there
are no collisions at all for dicts indexed by a contiguous range of ints.
The same is approximately true when keys are "consecutive" strings. So this
gives better-than-random behavior in common cases, and that's very desirable.
"""
----------
assignee: christian.heimes
messages: 211525
nosy: christian.heimes, rhettinger
priority: low
severity: normal
status: open
title: Update comments in dictobject.c
versions: Python 3.4
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20674>
_______________________________________
More information about the New-bugs-announce
mailing list