Removed the term count stuff from all rsets, and fixed what ever that broke.
[idzebra-moved-to-github.git] / rset / rset.c
1 /* $Id: rset.c,v 1.25 2004-08-20 14:44:46 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
3    Index Data Aps
4
5 This file is part of the Zebra server.
6
7 Zebra is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Zebra is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Zebra; see the file LICENSE.zebra.  If not, write to the
19 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
21 */
22
23
24
25 #include <stdio.h>
26 #include <string.h>
27 #include <zebrautl.h>
28 #include <assert.h>
29
30 #include <rset.h>
31 /* #include <../index/index.h> */ /* for log_keydump. Debugging only */
32
33 RSET rset_create(const struct rset_control *sel, void *parms)
34 {
35     RSET rnew;
36
37     logf (LOG_DEBUG, "rs_create(%s)", sel->desc);
38     rnew = (RSET) xmalloc(sizeof(*rnew));
39     rnew->control = sel;
40     rnew->flags = 0;
41     rnew->count = 1;
42     rnew->buf = (*sel->f_create)(rnew, sel, parms);
43     return rnew;
44 }
45
46 void rset_delete (RSET rs)
47 {
48     (rs->count)--;
49     if (!rs->count)
50     {
51         (*rs->control->f_delete)(rs);
52         xfree(rs);
53     }
54 }
55
56 RSET rset_dup (RSET rs)
57 {
58     (rs->count)++;
59     return rs;
60 }
61
62 void rset_default_pos (RSFD rfd, double *current, double *total)
63 { /* This should never really be needed, but it is still used in */
64   /* those rsets that we don't really plan to use, like isam-s */
65     assert(rfd);
66     assert(current);
67     assert(total);
68     *current=-1; /* signal that pos is not implemented */
69     *total=-1;
70 } /* rset_default_pos */
71
72 int rset_default_forward(RSET ct, RSFD rfd, void *buf, 
73                            int (*cmpfunc)(const void *p1, const void *p2), 
74                            const void *untilbuf)
75 {
76     int more=1;
77     int cmp=2;
78     logf (LOG_DEBUG, "rset_default_forward starting '%s' (ct=%p rfd=%p)",
79                     ct->control->desc, ct,rfd);
80     /* key_logdump(LOG_DEBUG, untilbuf); */
81     while ( (cmp==2) && (more))
82     {
83         logf (LOG_DEBUG, "rset_default_forward looping m=%d c=%d",more,cmp);
84         more=rset_read(ct, rfd, buf);
85         if (more)
86             cmp=(*cmpfunc)(untilbuf,buf);
87 /*        if (more)
88             key_logdump(LOG_DEBUG,buf); */
89     }
90     logf (LOG_DEBUG, "rset_default_forward exiting m=%d c=%d",more,cmp);
91
92     return more;
93 }
94