diff options
| author | Larry Hastings <larry@hastings.org> | 2014-01-06 15:24:19 (GMT) | 
|---|---|---|
| committer | Larry Hastings <larry@hastings.org> | 2014-01-06 15:24:19 (GMT) | 
| commit | b7f5dcadf2a929a92cfd5d0386426bc143cb01b4 (patch) | |
| tree | d3ee3564eac5ff32bf9db2f90907f1979969918b /Objects/setobject.c | |
| parent | e7ee44e9ba36fe6220ebb31c5c7faad5cfb2a250 (diff) | |
| parent | 74fc8c47f66da5673ed733d21e9014e9508f2819 (diff) | |
| download | cpython-b7f5dcadf2a929a92cfd5d0386426bc143cb01b4.zip cpython-b7f5dcadf2a929a92cfd5d0386426bc143cb01b4.tar.gz cpython-b7f5dcadf2a929a92cfd5d0386426bc143cb01b4.tar.bz2 | |
Merge 3.4.0b2 release revisions back into mainline.
Diffstat (limited to 'Objects/setobject.c')
| -rw-r--r-- | Objects/setobject.c | 15 | 
1 files changed, 14 insertions, 1 deletions
| diff --git a/Objects/setobject.c b/Objects/setobject.c index b0803f6..fa6a6d0 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -738,6 +738,17 @@ set_traverse(PySetObject *so, visitproc visit, void *arg)  static Py_hash_t  frozenset_hash(PyObject *self)  { +    /* Most of the constants in this hash algorithm are randomly choosen +       large primes with "interesting bit patterns" and that passed +       tests for good collision statistics on a variety of problematic +       datasets such as: + +          ps = [] +          for r in range(21): +              ps += itertools.combinations(range(20), r) +          num_distinct_hashes = len({hash(frozenset(s)) for s in ps}) + +    */      PySetObject *so = (PySetObject *)self;      Py_uhash_t h, hash = 1927868237UL;      setentry *entry; @@ -754,8 +765,10 @@ frozenset_hash(PyObject *self)             hashes so that many distinct combinations collapse to only             a handful of distinct hash values. */          h = entry->hash; -        hash ^= (h ^ (h << 16) ^ 89869747UL)  * 3644798167UL; +        hash ^= ((h ^ 89869747UL) ^ (h << 16)) * 3644798167UL;      } +    /* Make the final result spread-out in a different pattern +       than the algorithem for tuples or other python objects. */      hash = hash * 69069U + 907133923UL;      if (hash == -1)          hash = 590923713UL; | 
