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

ht_find.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_find.c,v 1.3 2006/07/13 05:36:16 klmitch Exp $
00020 */
00028 #include "dbprim.h"
00029 #include "dbprim_int.h"
00030 
00031 RCSTAG("@(#)$Id: ht_find.c,v 1.3 2006/07/13 05:36:16 klmitch Exp $");
00032 
00033 unsigned long
00034 ht_find(hash_table_t *table, hash_entry_t **entry_p, db_key_t *key)
00035 {
00036   unsigned long hash;
00037   link_elem_t *elem;
00038 
00039   initialize_dbpr_error_table(); /* initialize error table */
00040 
00041   if (!ht_verify(table) || !key) /* verify arguments */
00042     return DB_ERR_BADARGS;
00043 
00044   if (!table->ht_count) /* no entries in table... */
00045     return DB_ERR_NOENTRY;
00046 
00047   hash = (*table->ht_func)(table, key) % table->ht_modulus; /* get hash */
00048 
00049   /* walk through each element in that section */
00050   for (elem = ll_first(&table->ht_table[hash]); elem; elem = le_next(elem))
00051     /* compare keys... */
00052     if (!(*table->ht_comp)(table, key,
00053                            he_key((hash_entry_t *)le_object(elem)))) {
00054       /* found one, return it */
00055       if (entry_p)
00056         *entry_p = le_object(elem);
00057       return 0;
00058     }
00059 
00060   return DB_ERR_NOENTRY; /* couldn't find a matching entry */
00061 }

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