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
95c0d675
Kaydet (Commit)
95c0d675
authored
Eyl 01, 2013
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Further reduce the cost of hash collisions by inspecting an additional nearby entry.
üst
34567ec9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
4 deletions
+39
-4
setobject.c
Objects/setobject.c
+39
-4
No files found.
Objects/setobject.c
Dosyayı görüntüle @
95c0d675
...
@@ -65,10 +65,11 @@ chaining would be substantial (100% with typical malloc overhead).
...
@@ -65,10 +65,11 @@ chaining would be substantial (100% with typical malloc overhead).
The initial probe index is computed as hash mod the table size. Subsequent
The initial probe index is computed as hash mod the table size. Subsequent
probe indices are computed as explained in Objects/dictobject.c.
probe indices are computed as explained in Objects/dictobject.c.
To improve cache locality, each probe is done in pairs.
To improve cache locality, each probe inspects nearby entries before
After the probe is examined, an adjacent entry is then examined as well.
moving on to probes elsewhere in memory. Depending on alignment and the
The likelihood is that an adjacent entry is in the same cache line and
size of a cache line, the nearby entries are cheaper to inspect than
can be examined more cheaply than another probe elsewhere in memory.
other probes elsewhere in memory. This probe strategy reduces the cost
of hash collisions.
All arithmetic on hash should ignore overflow.
All arithmetic on hash should ignore overflow.
...
@@ -130,6 +131,26 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
...
@@ -130,6 +131,26 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
if
(
entry
->
key
==
dummy
&&
freeslot
==
NULL
)
if
(
entry
->
key
==
dummy
&&
freeslot
==
NULL
)
freeslot
=
entry
;
freeslot
=
entry
;
entry
=
&
table
[
j
^
2
];
if
(
entry
->
key
==
NULL
)
break
;
if
(
entry
->
key
==
key
)
return
entry
;
if
(
entry
->
hash
==
hash
&&
entry
->
key
!=
dummy
)
{
PyObject
*
startkey
=
entry
->
key
;
Py_INCREF
(
startkey
);
cmp
=
PyObject_RichCompareBool
(
startkey
,
key
,
Py_EQ
);
Py_DECREF
(
startkey
);
if
(
cmp
<
0
)
return
NULL
;
if
(
table
!=
so
->
table
||
entry
->
key
!=
startkey
)
return
set_lookkey
(
so
,
key
,
hash
);
if
(
cmp
>
0
)
return
entry
;
}
if
(
entry
->
key
==
dummy
&&
freeslot
==
NULL
)
freeslot
=
entry
;
i
=
i
*
5
+
perturb
+
1
;
i
=
i
*
5
+
perturb
+
1
;
j
=
i
&
mask
;
j
=
i
&
mask
;
perturb
>>=
PERTURB_SHIFT
;
perturb
>>=
PERTURB_SHIFT
;
...
@@ -190,6 +211,17 @@ set_lookkey_unicode(PySetObject *so, PyObject *key, Py_hash_t hash)
...
@@ -190,6 +211,17 @@ set_lookkey_unicode(PySetObject *so, PyObject *key, Py_hash_t hash)
if
(
entry
->
key
==
dummy
&&
freeslot
==
NULL
)
if
(
entry
->
key
==
dummy
&&
freeslot
==
NULL
)
freeslot
=
entry
;
freeslot
=
entry
;
entry
=
&
table
[
j
^
2
];
if
(
entry
->
key
==
NULL
)
break
;
if
(
entry
->
key
==
key
||
(
entry
->
hash
==
hash
&&
entry
->
key
!=
dummy
&&
unicode_eq
(
entry
->
key
,
key
)))
return
entry
;
if
(
entry
->
key
==
dummy
&&
freeslot
==
NULL
)
freeslot
=
entry
;
i
=
i
*
5
+
perturb
+
1
;
i
=
i
*
5
+
perturb
+
1
;
j
=
i
&
mask
;
j
=
i
&
mask
;
perturb
>>=
PERTURB_SHIFT
;
perturb
>>=
PERTURB_SHIFT
;
...
@@ -256,6 +288,9 @@ set_insert_clean(PySetObject *so, PyObject *key, Py_hash_t hash)
...
@@ -256,6 +288,9 @@ set_insert_clean(PySetObject *so, PyObject *key, Py_hash_t hash)
if
(
entry
->
key
==
NULL
)
if
(
entry
->
key
==
NULL
)
break
;
break
;
entry
=
&
table
[
j
^
1
];
entry
=
&
table
[
j
^
1
];
if
(
entry
->
key
==
NULL
)
break
;
entry
=
&
table
[
j
^
2
];
if
(
entry
->
key
==
NULL
)
if
(
entry
->
key
==
NULL
)
break
;
break
;
i
=
i
*
5
+
perturb
+
1
;
i
=
i
*
5
+
perturb
+
1
;
...
...
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