00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 #include <stdlib.h>
00029
00030 #include "dbprim.h"
00031 #include "dbprim_int.h"
00032
00033 RCSTAG("@(#)$Id: ht__flush_8c-source.html,v 1.3 2006/09/04 15:12:16 spale Exp $");
00034
00035 unsigned long
00036 ht_flush(hash_table_t *table, hash_iter_t flush_func, void *extra)
00037 {
00038 unsigned long retval = 0;
00039 int i;
00040 link_elem_t *elem;
00041
00042 initialize_dbpr_error_table();
00043
00044 if (!ht_verify(table))
00045 return DB_ERR_BADARGS;
00046
00047 if (table->ht_flags & HASH_FLAG_FREEZE)
00048 return DB_ERR_FROZEN;
00049
00050
00051 for (i = 0; i < table->ht_modulus; i++)
00052 for (elem = ll_first(&table->ht_table[i]); elem;
00053 elem = ll_first(&table->ht_table[i])) {
00054 ht_remove(table, le_object(elem));
00055
00056 table->ht_flags |= HASH_FLAG_FREEZE;
00057
00058 if (flush_func)
00059 retval = (*flush_func)(table, le_object(elem), extra);
00060
00061 table->ht_flags &= ~HASH_FLAG_FREEZE;
00062
00063 if (retval)
00064 return retval;
00065 }
00066
00067 table->ht_count = 0;
00068
00069 if (table->ht_flags & HASH_FLAG_AUTOSHRINK)
00070 return ht_free(table);
00071
00072 return 0;
00073 }