2 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
4 ** This library is free software; you can redistribute it and/or
5 ** modify it under the terms of the GNU Library General Public
6 ** License as published by the Free Software Foundation; either
7 ** version 2 of the License, or (at your option) any later version.
9 ** This library is distributed in the hope that it will be useful,
10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 ** Library General Public License for more details.
14 ** You should have received a copy of the GNU Library General Public
15 ** License along with this library; if not, write to the Free
16 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 #include "dbprim_int.h"
26 /** \ingroup dbprim_hash
27 * \brief Remove an element from a hash table.
29 * This function removes the given element from the specified hash
32 * \param table A pointer to a #hash_table_t.
33 * \param entry A pointer to a #hash_entry_t to be removed from the
36 * \retval DB_ERR_BADARGS An invalid argument was given.
37 * \retval DB_ERR_UNUSED Entry is not in a hash table.
38 * \retval DB_ERR_WRONGTABLE Entry is not in this hash table.
39 * \retval DB_ERR_FROZEN Hash table is frozen.
40 * \retval DB_ERR_UNRECOVERABLE An unrecoverable error occurred while
44 ht_remove(hash_table_t *table, hash_entry_t *entry)
46 unsigned long retval = 0;
48 initialize_dbpr_error_table(); /* initialize error table */
50 if (!ht_verify(table) || !he_verify(entry)) /* verify arguments */
51 return DB_ERR_BADARGS;
53 if (!entry->he_table) /* it's not in a table */
55 if (entry->he_table != table) /* it's in the wrong table */
56 return DB_ERR_WRONGTABLE;
58 if (table->ht_flags & HASH_FLAG_FREEZE) /* don't remove from frozen tables */
61 /* remove the entry from the table */
62 if ((retval = ll_remove(&table->ht_table[entry->he_hash], &entry->he_elem)))
65 entry->he_table = 0; /* reset the table */
67 /* decrement element count and shrink the table if necessary and allowed */
68 if (--table->ht_count < table->ht_rollunder &&
69 (table->ht_flags & HASH_FLAG_AUTOSHRINK))
70 retval = ht_resize(table, 0);