mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Small rearrangement to bring together the three functions for probing the hash table.
This commit is contained in:
parent
ae7b00e2d3
commit
04fd9dd52b
1 changed files with 39 additions and 32 deletions
|
@ -64,6 +64,9 @@ PyObject *_PySet_Dummy = dummy;
|
||||||
static PySetObject *free_list[PySet_MAXFREELIST];
|
static PySetObject *free_list[PySet_MAXFREELIST];
|
||||||
static int numfree = 0;
|
static int numfree = 0;
|
||||||
|
|
||||||
|
/* ======================================================================== */
|
||||||
|
/* ======= Begin logic for probing the hash table ========================= */
|
||||||
|
|
||||||
static setentry *
|
static setentry *
|
||||||
set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
|
set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
{
|
{
|
||||||
|
@ -197,38 +200,6 @@ set_lookkey_unicode(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
return freeslot == NULL ? entry : freeslot;
|
return freeslot == NULL ? entry : freeslot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Internal routine to insert a new key into the table.
|
|
||||||
Used by the public insert routine.
|
|
||||||
Eats a reference to key.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash)
|
|
||||||
{
|
|
||||||
setentry *entry;
|
|
||||||
|
|
||||||
assert(so->lookup != NULL);
|
|
||||||
entry = so->lookup(so, key, hash);
|
|
||||||
if (entry == NULL)
|
|
||||||
return -1;
|
|
||||||
if (entry->key == NULL) {
|
|
||||||
/* UNUSED */
|
|
||||||
so->fill++;
|
|
||||||
entry->key = key;
|
|
||||||
entry->hash = hash;
|
|
||||||
so->used++;
|
|
||||||
} else if (entry->key == dummy) {
|
|
||||||
/* DUMMY */
|
|
||||||
entry->key = key;
|
|
||||||
entry->hash = hash;
|
|
||||||
so->used++;
|
|
||||||
} else {
|
|
||||||
/* ACTIVE */
|
|
||||||
Py_DECREF(key);
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Internal routine used by set_table_resize() to insert an item which is
|
Internal routine used by set_table_resize() to insert an item which is
|
||||||
known to be absent from the set. This routine also assumes that
|
known to be absent from the set. This routine also assumes that
|
||||||
|
@ -266,6 +237,42 @@ set_insert_clean(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
so->used++;
|
so->used++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ======== End logic for probing the hash table ========================== */
|
||||||
|
/* ======================================================================== */
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
Internal routine to insert a new key into the table.
|
||||||
|
Used by the public insert routine.
|
||||||
|
Eats a reference to key.
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
set_insert_key(PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
|
{
|
||||||
|
setentry *entry;
|
||||||
|
|
||||||
|
assert(so->lookup != NULL);
|
||||||
|
entry = so->lookup(so, key, hash);
|
||||||
|
if (entry == NULL)
|
||||||
|
return -1;
|
||||||
|
if (entry->key == NULL) {
|
||||||
|
/* UNUSED */
|
||||||
|
so->fill++;
|
||||||
|
entry->key = key;
|
||||||
|
entry->hash = hash;
|
||||||
|
so->used++;
|
||||||
|
} else if (entry->key == dummy) {
|
||||||
|
/* DUMMY */
|
||||||
|
entry->key = key;
|
||||||
|
entry->hash = hash;
|
||||||
|
so->used++;
|
||||||
|
} else {
|
||||||
|
/* ACTIVE */
|
||||||
|
Py_DECREF(key);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Restructure the table by allocating a new table and reinserting all
|
Restructure the table by allocating a new table and reinserting all
|
||||||
keys again. When entries have been deleted, the new table may
|
keys again. When entries have been deleted, the new table may
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue