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
8408dc58
Kaydet (Commit)
8408dc58
authored
Eyl 15, 2013
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 18771: Make it possible to set the number linear probes at compile-time.
üst
e6d35dba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
7 deletions
+28
-7
3.4.rst
Doc/whatsnew/3.4.rst
+9
-2
setobject.c
Objects/setobject.c
+19
-5
No files found.
Doc/whatsnew/3.4.rst
Dosyayı görüntüle @
8408dc58
...
...
@@ -444,8 +444,15 @@ Major performance enhancements have been added:
* The UTF-32 decoder is now 3x to 4x faster.
* The cost of hash collisions for sets is now reduced. Each hash table
probe now checks a second key/hash pair for each cache line retrieved.
This exploits cache locality to make collision resolution less expensive.
probe now checks a series of consecutive, adjacent key/hash pairs before
continuing to make random probes through the hash table. This exploits
cache locality to make collision resolution less expensive.
The collision resolution scheme can be described as a hybrid of linear
probing and open addressing. The number of additional linear probes
defaults to nine. This can be changed at compile-time by defining
LINEAR_PROBES to be any value. Set LINEAR_PROBES=0 to turn-off
linear probing entirely.
(Contributed by Raymond Hettinger in :issue"`18771`.)
...
...
Objects/setobject.c
Dosyayı görüntüle @
8408dc58
...
...
@@ -44,7 +44,9 @@ PyObject *_PySet_Dummy = dummy;
/* ======= Begin logic for probing the hash table ========================= */
/* This should be >= PySet_MINSIZE - 1 */
#ifndef LINEAR_PROBES
#define LINEAR_PROBES 9
#endif
/* This must be >= 1 */
#define PERTURB_SHIFT 5
...
...
@@ -55,12 +57,14 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
setentry
*
table
=
so
->
table
;
setentry
*
freeslot
=
NULL
;
setentry
*
entry
;
setentry
*
limit
;
size_t
perturb
=
hash
;
size_t
mask
=
so
->
mask
;
size_t
i
=
(
size_t
)
hash
;
/* Unsigned for defined overflow behavior. */
size_t
j
;
int
cmp
;
#if LINEAR_PROBES
setentry
*
limit
;
size_t
j
;
#endif
entry
=
&
table
[
i
&
mask
];
if
(
entry
->
key
==
NULL
)
...
...
@@ -84,6 +88,7 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
if
(
entry
->
key
==
dummy
&&
freeslot
==
NULL
)
freeslot
=
entry
;
#if LINEAR_PROBES
limit
=
&
table
[
mask
];
for
(
j
=
0
;
j
<
LINEAR_PROBES
;
j
++
)
{
entry
=
(
entry
==
limit
)
?
&
table
[
0
]
:
entry
+
1
;
...
...
@@ -106,13 +111,14 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
if
(
entry
->
key
==
dummy
&&
freeslot
==
NULL
)
freeslot
=
entry
;
}
#endif
perturb
>>=
PERTURB_SHIFT
;
i
=
i
*
5
+
1
+
perturb
;
entry
=
&
table
[
i
&
mask
];
if
(
entry
->
key
==
NULL
)
break
;
goto
found_null
;
}
found_null:
return
freeslot
==
NULL
?
entry
:
freeslot
;
...
...
@@ -129,11 +135,13 @@ set_lookkey_unicode(PySetObject *so, PyObject *key, Py_hash_t hash)
setentry
*
table
=
so
->
table
;
setentry
*
freeslot
=
NULL
;
setentry
*
entry
;
setentry
*
limit
;
size_t
perturb
=
hash
;
size_t
mask
=
so
->
mask
;
size_t
i
=
(
size_t
)
hash
;
#if LINEAR_PROBES
setentry
*
limit
;
size_t
j
;
#endif
/* Make sure this function doesn't have to handle non-unicode keys,
including subclasses of str; e.g., one reason to subclass
...
...
@@ -157,6 +165,7 @@ set_lookkey_unicode(PySetObject *so, PyObject *key, Py_hash_t hash)
if
(
entry
->
key
==
dummy
&&
freeslot
==
NULL
)
freeslot
=
entry
;
#if LINEAR_PROBES
limit
=
&
table
[
mask
];
for
(
j
=
0
;
j
<
LINEAR_PROBES
;
j
++
)
{
entry
=
(
entry
==
limit
)
?
&
table
[
0
]
:
entry
+
1
;
...
...
@@ -170,13 +179,14 @@ set_lookkey_unicode(PySetObject *so, PyObject *key, Py_hash_t hash)
if
(
entry
->
key
==
dummy
&&
freeslot
==
NULL
)
freeslot
=
entry
;
}
#endif
perturb
>>=
PERTURB_SHIFT
;
i
=
i
*
5
+
1
+
perturb
;
entry
=
&
table
[
i
&
mask
];
if
(
entry
->
key
==
NULL
)
break
;
goto
found_null
;
}
found_null:
return
freeslot
==
NULL
?
entry
:
freeslot
;
...
...
@@ -198,17 +208,21 @@ set_insert_clean(PySetObject *so, PyObject *key, Py_hash_t hash)
size_t
perturb
=
hash
;
size_t
mask
=
(
size_t
)
so
->
mask
;
size_t
i
=
(
size_t
)
hash
;
#if LINEAR_PROBES
size_t
j
;
#endif
while
(
1
)
{
entry
=
&
table
[
i
&
mask
];
if
(
entry
->
key
==
NULL
)
goto
found_null
;
#if LINEAR_PROBES
for
(
j
=
1
;
j
<=
LINEAR_PROBES
;
j
++
)
{
entry
=
&
table
[(
i
+
j
)
&
mask
];
if
(
entry
->
key
==
NULL
)
goto
found_null
;
}
#endif
perturb
>>=
PERTURB_SHIFT
;
i
=
i
*
5
+
1
+
perturb
;
}
...
...
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