diff options
author | Raymond Hettinger <python@rcn.com> | 2013-09-08 00:41:01 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2013-09-08 00:41:01 (GMT) |
commit | 04fd9dd52bc81041126cb8df86a5e7629113a193 (patch) | |
tree | a8bb310577d6aa84e84598bff08224c4180f1235 /Objects/setobject.c | |
parent | ae7b00e2d3b92991ef1d7685f2bd4b15e5263b84 (diff) | |
download | cpython-04fd9dd52bc81041126cb8df86a5e7629113a193.zip cpython-04fd9dd52bc81041126cb8df86a5e7629113a193.tar.gz cpython-04fd9dd52bc81041126cb8df86a5e7629113a193.tar.bz2 |
Small rearrangement to bring together the three functions for probing the hash table.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r-- | Objects/setobject.c | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c index b63a966..362273a 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -64,6 +64,9 @@ PyObject *_PySet_Dummy = dummy; static PySetObject *free_list[PySet_MAXFREELIST]; static int numfree = 0; +/* ======================================================================== */ +/* ======= Begin logic for probing the hash table ========================= */ + static setentry * set_lookkey(PySetObject *so, PyObject *key, Py_hash_t hash) { @@ -198,38 +201,6 @@ set_lookkey_unicode(PySetObject *so, PyObject *key, Py_hash_t hash) } /* -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 known to be absent from the set. This routine also assumes that the set contains no deleted entries. Besides the performance benefit, @@ -266,6 +237,42 @@ set_insert_clean(PySetObject *so, PyObject *key, Py_hash_t hash) 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 keys again. When entries have been deleted, the new table may |