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 Find an entry in a hash table.
29 * This function looks up an entry matching the given \p key.
31 * \param table A pointer to a #hash_table_t.
33 * A pointer to a pointer to a #hash_entry_t. This is a
34 * result parameter. If \c NULL is passed, the lookup
35 * will be performed and an appropriate error code
37 * \param key A pointer to a #db_key_t describing the item to find.
39 * \retval DB_ERR_BADARGS An argument was invalid.
40 * \retval DB_ERR_NOENTRY No matching entry was found.
43 ht_find(hash_table_t *table, hash_entry_t **entry_p, db_key_t *key)
48 initialize_dbpr_error_table(); /* initialize error table */
50 if (!ht_verify(table) || !key) /* verify arguments */
51 return DB_ERR_BADARGS;
53 if (!table->ht_count) /* no entries in table... */
54 return DB_ERR_NOENTRY;
56 hash = (*table->ht_func)(table, key) % table->ht_modulus; /* get hash */
58 /* walk through each element in that section */
59 for (elem = ll_first(&table->ht_table[hash]); elem; elem = le_next(elem))
61 if (!(*table->ht_comp)(table, key,
62 he_key((hash_entry_t *)le_object(elem)))) {
63 /* found one, return it */
65 *entry_p = le_object(elem);
69 return DB_ERR_NOENTRY; /* couldn't find a matching entry */