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 Iterate over each entry in a hash table.
29 * This function iterates over every entry in a hash table (in an
30 * unspecified order), executing the given \p iter_func on each entry.
32 * \param table A pointer to a #hash_table_t.
34 * A pointer to a callback function used to perform
35 * user-specified actions on an entry in a hash table. \c
36 * NULL is an invalid value. See the documentation for
37 * #hash_iter_t for more information.
38 * \param extra A \c void pointer that will be passed to \p
41 * \retval DB_ERR_BADARGS An argument was invalid.
42 * \retval DB_ERR_FROZEN The hash table is frozen.
45 ht_iter(hash_table_t *table, hash_iter_t iter_func, void *extra)
51 initialize_dbpr_error_table(); /* initialize error table */
53 if (!ht_verify(table) || !iter_func) /* verify arguments */
54 return DB_ERR_BADARGS;
56 if (table->ht_flags & HASH_FLAG_FREEZE) /* don't mess with frozen tables */
59 table->ht_flags |= HASH_FLAG_FREEZE; /* freeze the table */
61 /* walk through all the elements and call the iteration function */
62 for (i = 0; i < table->ht_modulus; i++)
63 for (elem = ll_first(&table->ht_table[i]); elem; elem = le_next(elem))
64 if ((retval = (*iter_func)(table, le_object(elem), extra))) {
65 table->ht_flags &= ~HASH_FLAG_FREEZE; /* unfreeze the table */
69 table->ht_flags &= ~HASH_FLAG_FREEZE; /* unfreeze the table */