Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals

ht_remove.c

Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
00003 **
00004 ** This library is free software; you can redistribute it and/or
00005 ** modify it under the terms of the GNU Library General Public
00006 ** License as published by the Free Software Foundation; either
00007 ** version 2 of the License, or (at your option) any later version.
00008 **
00009 ** This library is distributed in the hope that it will be useful,
00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012 ** Library General Public License for more details.
00013 **
00014 ** You should have received a copy of the GNU Library General Public
00015 ** License along with this library; if not, write to the Free
00016 ** Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00017 ** MA 02111-1307, USA
00018 **
00019 ** @(#)$Id: ht_remove.c,v 1.5 2006/07/13 05:36:16 klmitch Exp $
00020 */
00028 #include "dbprim.h"
00029 #include "dbprim_int.h"
00030 
00031 RCSTAG("@(#)$Id: ht_remove.c,v 1.5 2006/07/13 05:36:16 klmitch Exp $");
00032 
00033 unsigned long
00034 ht_remove(hash_table_t *table, hash_entry_t *entry)
00035 {
00036   unsigned long retval = 0;
00037 
00038   initialize_dbpr_error_table(); /* initialize error table */
00039 
00040   if (!ht_verify(table) || !he_verify(entry)) /* verify arguments */
00041     return DB_ERR_BADARGS;
00042 
00043   if (!entry->he_table) /* it's not in a table */
00044     return DB_ERR_UNUSED;
00045   if (entry->he_table != table) /* it's in the wrong table */
00046     return DB_ERR_WRONGTABLE;
00047 
00048   if (table->ht_flags & HASH_FLAG_FREEZE) /* don't remove from frozen tables */
00049     return DB_ERR_FROZEN;
00050 
00051   /* try to shrink the table if necessary... */
00052   if ((table->ht_count - 1) < table->ht_rollunder &&
00053       (table->ht_flags & HASH_FLAG_AUTOSHRINK) &&
00054       (retval = ht_resize(table, table->ht_count - 1)))
00055     return retval; /* if we try to shrink and it won't, error out */
00056 
00057   /* remove the entry from the table */
00058   if ((retval = ll_remove(&table->ht_table[entry->he_hash], &entry->he_elem)))
00059     return retval;
00060 
00061   entry->he_table = 0; /* reset the table */
00062 
00063   table->ht_count--; /* decrement element count */
00064 
00065   return retval;
00066 }

Generated on Sat Jul 15 14:10:33 2006 for DatabasePrimitivesLibrary by  doxygen 1.4.4