Accept topic changes from servers that do not send topic-set timestamps (fixes SF...
[ircu2.10.12-pk.git] / libs / dbprim / sh_iter.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 _sh_iter_s {
27   smat_table_t *si_table;       /* pointer to the smat table */
28   smat_iter_t   si_iter;        /* iter function */
29   void         *si_extra;       /* extra data */
30 };
31
32 static unsigned long
33 _sh_iter_iter(link_head_t *head, link_elem_t *elem, void *extra)
34 {
35   struct _sh_iter_s *si;
36
37   si = extra;
38
39   /* call the user iteration function--with appropriate translation */
40   return (*si->si_iter)(si->si_table, le_object(elem), si->si_extra);
41 }
42
43 /** \ingroup dbprim_smat
44  * \brief Iterate over each entry in a row or column of a sparse
45  * matrix.
46  *
47  * This function iterates over a row or column of a sparse matrix,
48  * executing the given \p iter_func for each entry.
49  *
50  * \param head  A pointer to a #smat_head_t.
51  * \param iter_func
52  *              A pointer to a callback function used to perform
53  *              user-specified actions on an entry in a row or column
54  *              of a sparse matrix.  \c NULL is an invalid value.  See
55  *              the documentation for #smat_iter_t for more
56  *              information.
57  * \param extra A \c void pointer that will be passed to \p
58  *              iter_func.
59  *
60  * \retval DB_ERR_BADARGS       An argument was invalid.
61  */
62 unsigned long
63 sh_iter(smat_head_t *head, smat_iter_t iter_func, void *extra)
64 {
65   struct _sh_iter_s si;
66
67   initialize_dbpr_error_table(); /* initialize error table */
68
69   if (!sh_verify(head) || !iter_func) /* verify arguments */
70     return DB_ERR_BADARGS;
71
72   /* initialize extra data... */
73   si.si_table = head->sh_table;
74   si.si_iter = iter_func;
75   si.si_extra = extra;
76
77   /* call into linked list library to iterate over the list */
78   return ll_iter(&head->sh_head, _sh_iter_iter, &si);
79 }