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"
27 smat_table_t *sf_table; /* pointer to the smat table */
28 smat_iter_t sf_flush; /* flush function */
29 void *sf_extra; /* extra data */
33 _st_flush_iter(hash_table_t *table, hash_entry_t *ent, void *extra)
35 unsigned long retval = 0;
36 struct _st_flush_s *sf;
40 /* Remove the object from all lists first */
41 _st_remove(sf->sf_table, he_value(ent), ST_REM_FIRST | ST_REM_SECOND);
43 /* call the user flush function if so desired */
45 retval = (*sf->sf_flush)(sf->sf_table, he_value(ent), sf->sf_extra);
47 _smat_free(he_value(ent)); /* destroy the entry */
52 /** \ingroup dbprim_smat
53 * \brief Flush a sparse matrix.
55 * This function flushes a sparse matrix--that is, it removes each
56 * entry from the matrix. If a \p flush_func is specified, it will be
57 * called on the entry after it has been removed from the table, and
58 * may safely call <CODE>free()</CODE>.
60 * \param table A pointer to a #smat_table_t.
62 * A pointer to a callback function used to perform
63 * user-specified actions on an entry after removing it
64 * from the table. May be \c NULL. See the
65 * documentation for #smat_iter_t for more information.
66 * \param extra A \c void pointer that will be passed to \p
69 * \retval DB_ERR_BADARGS An argument was invalid.
70 * \retval DB_ERR_FROZEN The sparse matrix is frozen.
73 st_flush(smat_table_t *table, smat_iter_t flush_func, void *extra)
75 struct _st_flush_s sf;
77 initialize_dbpr_error_table(); /* initialize error table */
79 if (!st_verify(table)) /* verify arguments */
80 return DB_ERR_BADARGS;
82 /* initialize extra data... */
84 sf.sf_flush = flush_func;
87 /* call into linked list library to flush the list */
88 return ht_flush(&table->st_table, _st_flush_iter, &sf);