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_loc_t sf_elem; /* which list we're traversing */
29 smat_iter_t sf_flush; /* flush function */
30 void *sf_extra; /* extra data */
34 _sh_flush_iter(link_head_t *head, link_elem_t *elem, void *extra)
36 unsigned long retval = 0;
37 struct _sh_flush_s *sf;
41 /* Remove the object from all lists first */
42 if (_st_remove(sf->sf_table, le_object(elem), ST_REM_HASH |
43 (sf->sf_elem == SMAT_LOC_FIRST ? ST_REM_SECOND :
45 return DB_ERR_UNRECOVERABLE;
47 /* call the user flush function if so desired */
49 retval = (*sf->sf_flush)(sf->sf_table, le_object(elem), sf->sf_extra);
51 _smat_free(le_object(elem)); /* destroy the entry */
56 /** ingroup dbprim_smat
57 * \brief Flush a row or column of a sparse matrix.
59 * This function flushes a sparse matrix row or column--that is, it
60 * removes each element from that row or column. If a \p flush_func
61 * is specified, it will be called on the entry after it has been
62 * removed from the row or column, and may safely call
63 * <CODE>free()</CODE>.
65 * \param list A pointer to a #smat_head_t.
67 * A pointer to a callback function used to perform
68 * user-specifed actions on an entry after removing it
69 * from the row or column. May be \c NULL. See the
70 * documentation for #smat_iter_t for more information.
71 * \param extra A \c void pointer that will be passed to \p
74 * \retval DB_ERR_BADARGS An argument was invalid.
77 sh_flush(smat_head_t *head, smat_iter_t flush_func, void *extra)
79 struct _sh_flush_s sf;
81 initialize_dbpr_error_table(); /* initialize error table */
83 if (!sh_verify(head)) /* verify arguments */
84 return DB_ERR_BADARGS;
86 /* initialize extra data... */
87 sf.sf_table = head->sh_table;
88 sf.sf_elem = head->sh_elem;
89 sf.sf_flush = flush_func;
92 /* call into linked list library to flush the list */
93 return ll_flush(&head->sh_head, _sh_flush_iter, &sf);