Skip to content

Improve code clarity for the set lookup logic #20028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Improve variable name
  • Loading branch information
rhettinger committed May 10, 2020
commit e650fefafd869c27395e57ccdea8a0ca0bdeaf1f
12 changes: 6 additions & 6 deletions Objects/setobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
size_t perturb = hash;
size_t mask = so->mask;
size_t i = (size_t)hash & mask; /* Unsigned for defined overflow behavior */
size_t j;
int probes;
int cmp;

while (1) {
entry = &so->table[i];
j = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0;
probes = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0;
do {
if (entry->hash == 0 && entry->key == NULL)
return entry;
Expand All @@ -91,7 +91,7 @@ set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
mask = so->mask;
}
entry++;
} while (j--);
} while (probes--);
perturb >>= PERTURB_SHIFT;
i = (i * 5 + 1 + perturb) & mask;
}
Expand All @@ -107,7 +107,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
size_t perturb;
size_t mask;
size_t i; /* Unsigned for defined overflow behavior */
size_t j;
int probes;
int cmp;

/* Pre-increment is necessary to prevent arbitrary code in the rich
Expand All @@ -122,7 +122,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)

while (1) {
entry = &so->table[i];
j = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0;
probes = (i + LINEAR_PROBES <= mask) ? LINEAR_PROBES: 0;
do {
if (entry->hash == 0 && entry->key == NULL)
goto found_unused;
Expand All @@ -148,7 +148,7 @@ set_add_entry(PySetObject *so, PyObject *key, Py_hash_t hash)
mask = so->mask;
}
entry++;
} while (j--);
} while (probes--);
perturb >>= PERTURB_SHIFT;
i = (i * 5 + 1 + perturb) & mask;
}
Expand Down