Skip to content

Commit 5cd87a8

Browse files
committed
Reduce load factor (from 66% to 60%) to improve effectiveness of linear probing.
Decreased density gives better collision statistics (average of 2.5 probes in a full table versus 3.0 previously) and fewer occurences of starting a second possibly overlapping sequence of 10 linear probes. Makes resizes a little more frequent but each with less work (fewer insertions and fewer collisions).
1 parent b451f91 commit 5cd87a8

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

Objects/setobject.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
234234
so->used++;
235235
entry->key = key;
236236
entry->hash = hash;
237-
if ((size_t)so->fill*3 < mask*2)
237+
if ((size_t)so->fill*5 < mask*3)
238238
return 0;
239239
return set_table_resize(so, so->used);
240240

@@ -642,7 +642,7 @@ set_merge(PySetObject *so, PyObject *otherset)
642642
* incrementally resizing as we insert new keys. Expect
643643
* that there will be no (or few) overlapping keys.
644644
*/
645-
if ((so->fill + other->used)*3 >= so->mask*2) {
645+
if ((so->fill + other->used)*5 >= so->mask*3) {
646646
if (set_table_resize(so, so->used + other->used) != 0)
647647
return -1;
648648
}
@@ -986,7 +986,7 @@ set_update_internal(PySetObject *so, PyObject *other)
986986
*/
987987
if (dictsize < 0)
988988
return -1;
989-
if ((so->fill + dictsize)*3 >= so->mask*2) {
989+
if ((so->fill + dictsize)*5 >= so->mask*3) {
990990
if (set_table_resize(so, so->used + dictsize) != 0)
991991
return -1;
992992
}

0 commit comments

Comments
 (0)