Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
74fc8c47
Kaydet (Commit)
74fc8c47
authored
Ock 05, 2014
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add comments to frozenset_hash().
Also, provide a minor hint to the compiler on how to group the xors.
üst
df3ed242
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
1 deletion
+14
-1
setobject.c
Objects/setobject.c
+14
-1
No files found.
Objects/setobject.c
Dosyayı görüntüle @
74fc8c47
...
@@ -738,6 +738,17 @@ set_traverse(PySetObject *so, visitproc visit, void *arg)
...
@@ -738,6 +738,17 @@ set_traverse(PySetObject *so, visitproc visit, void *arg)
static
Py_hash_t
static
Py_hash_t
frozenset_hash
(
PyObject
*
self
)
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
;
PySetObject
*
so
=
(
PySetObject
*
)
self
;
Py_uhash_t
h
,
hash
=
1927868237UL
;
Py_uhash_t
h
,
hash
=
1927868237UL
;
setentry
*
entry
;
setentry
*
entry
;
...
@@ -754,8 +765,10 @@ frozenset_hash(PyObject *self)
...
@@ -754,8 +765,10 @@ frozenset_hash(PyObject *self)
hashes so that many distinct combinations collapse to only
hashes so that many distinct combinations collapse to only
a handful of distinct hash values. */
a handful of distinct hash values. */
h
=
entry
->
hash
;
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
;
hash
=
hash
*
69069U
+
907133923UL
;
if
(
hash
==
-
1
)
if
(
hash
==
-
1
)
hash
=
590923713UL
;
hash
=
590923713UL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment