Accept topic changes from servers that do not send topic-set timestamps (fixes SF...
[ircu2.10.12-pk.git] / libs / dbprim / st_flush.c
1 /*
2 ** Copyright (C) 2002 by Kevin L. Mitchell <klmitch@mit.edu>
3 **
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.
8 **
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.
13 **
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,
17 ** MA 02111-1307, USA
18 **
19 ** @(#)$Id$
20 */
21 #include "dbprim.h"
22 #include "dbprim_int.h"
23
24 RCSTAG("@(#)$Id$");
25
26 struct _st_flush_s {
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 */
30 };
31
32 static unsigned long
33 _st_flush_iter(hash_table_t *table, hash_entry_t *ent, void *extra)
34 {
35   unsigned long retval = 0;
36   struct _st_flush_s *sf;
37
38   sf = extra;
39
40   /* Remove the object from all lists first */
41   _st_remove(sf->sf_table, he_value(ent), ST_REM_FIRST | ST_REM_SECOND);
42
43   /* call the user flush function if so desired */
44   if (sf->sf_flush)
45     retval = (*sf->sf_flush)(sf->sf_table, he_value(ent), sf->sf_extra);
46
47   _smat_free(he_value(ent)); /* destroy the entry */
48
49   return retval;
50 }
51
52 /** \ingroup dbprim_smat
53  * \brief Flush a sparse matrix.
54  *
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>.
59  *
60  * \param table A pointer to a #smat_table_t.
61  * \param flush_func
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
67  *              iter_func.
68  *
69  * \retval DB_ERR_BADARGS       An argument was invalid.
70  * \retval DB_ERR_FROZEN        The sparse matrix is frozen.
71  */
72 unsigned long
73 st_flush(smat_table_t *table, smat_iter_t flush_func, void *extra)
74 {
75   struct _st_flush_s sf;
76
77   initialize_dbpr_error_table(); /* initialize error table */
78
79   if (!st_verify(table)) /* verify arguments */
80     return DB_ERR_BADARGS;
81
82   /* initialize extra data... */
83   sf.sf_table = table;
84   sf.sf_flush = flush_func;
85   sf.sf_extra = extra;
86
87   /* call into linked list library to flush the list */
88   return ht_flush(&table->st_table, _st_flush_iter, &sf);
89 }