Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c70a2b7

Browse files
committed
Make the linear probe sequence clearer.
1 parent 1eb8762 commit c70a2b7

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

Objects/setobject.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
6262
size_t i = (size_t)hash; /* Unsigned for defined overflow behavior. */
6363
int cmp;
6464
#if LINEAR_PROBES
65-
setentry *limit;
6665
size_t j;
6766
#endif
6867

@@ -89,9 +88,8 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
8988
freeslot = entry;
9089

9190
#if LINEAR_PROBES
92-
limit = &table[mask];
93-
for (j = 0 ; j < LINEAR_PROBES ; j++) {
94-
entry = (entry == limit) ? &table[0] : entry + 1;
91+
for (j = 1 ; j <= LINEAR_PROBES ; j++) {
92+
entry = &table[(i + j) & mask];
9593
if (entry->key == NULL)
9694
goto found_null;
9795
if (entry->key == key)
@@ -139,7 +137,6 @@ set_lookkey_unicode(PySetObject *so, PyObject *key, Py_hash_t hash)
139137
size_t mask = so->mask;
140138
size_t i = (size_t)hash;
141139
#if LINEAR_PROBES
142-
setentry *limit;
143140
size_t j;
144141
#endif
145142

@@ -166,9 +163,8 @@ set_lookkey_unicode(PySetObject *so, PyObject *key, Py_hash_t hash)
166163
freeslot = entry;
167164

168165
#if LINEAR_PROBES
169-
limit = &table[mask];
170-
for (j = 0 ; j < LINEAR_PROBES ; j++) {
171-
entry = (entry == limit) ? &table[0] : entry + 1;
166+
for (j = 1 ; j <= LINEAR_PROBES ; j++) {
167+
entry = &table[(i + j) & mask];
172168
if (entry->key == NULL)
173169
goto found_null;
174170
if (entry->key == key

0 commit comments

Comments
 (0)