Commit eb28ef20 authored by Tim Peters's avatar Tim Peters

New collision resolution scheme: no polynomials, simpler, faster, less

code, less memory.  Tests have uncovered no drawbacks.  Christian and
Vladimir are the other two people who have burned many brain cells on the
dict code in recent years, and they like the approach too, so I'm checking
it in without further ado.
parent 951a8841
...@@ -15,7 +15,7 @@ Core ...@@ -15,7 +15,7 @@ Core
To enhance the usability of the .encode() method, the special To enhance the usability of the .encode() method, the special
casing of Unicode object return values was dropped (Unicode objects casing of Unicode object return values was dropped (Unicode objects
were auto-magically converted to string using the default encoding). were auto-magically converted to string using the default encoding).
Both methods will now return whatever the codec in charge of the Both methods will now return whatever the codec in charge of the
requested encoding returns as object, e.g. Unicode codecs will requested encoding returns as object, e.g. Unicode codecs will
return Unicode objects when decoding is requested ("äöü".decode("latin-1") return Unicode objects when decoding is requested ("äöü".decode("latin-1")
...@@ -116,13 +116,11 @@ Core ...@@ -116,13 +116,11 @@ Core
to crash if the element comparison routines for the dict keys and/or to crash if the element comparison routines for the dict keys and/or
values mutated the dicts. Making the code bulletproof slowed it down. values mutated the dicts. Making the code bulletproof slowed it down.
- Collisions in dicts now use polynomial division instead of multiplication - Collisions in dicts are resolved via a new approach, which can help
to generate the probe sequence, following an idea of Christian Tismer's. dramatically in bad cases. For example, looking up every key in a dict
This allows all bits of the hash code to come into play. It should have d with d.keys() = [i << 16 for i in range(20000)] is approximately 500x
little or no effect on speed in ordinary cases, but can help dramatically faster now. Thanks to Christian Tismer for pointing out the cause and
in bad cases. For example, looking up every key in a dict d with the nature of an effective cure (last December! better late than never).
d.keys() = [i << 16 for i in range(20000)] is approximately 500x faster
now.
Library Library
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment