Forgot to commit the new rset.h when removing rewind ops
[idzebra-moved-to-github.git] / include / rset.h
1 /* $Id: rset.h,v 1.36 2004-09-30 13:07:06 heikki Exp $
2    Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
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 #ifndef RSET_H
26 #define RSET_H
27
28 #include <stdlib.h>
29
30 /* unfortunately we need the isam includes here, for the arguments for */
31 /* rsisamX_create */
32 #include <isamb.h> 
33 #include <isamc.h> 
34 #include <isams.h> 
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 typedef struct rsfd *RSFD; /* Rset "file descriptor" */
41 typedef struct rset *RSET; /* Result set */
42
43 struct rsfd {  /* the stuff common to all rsfd's. */
44     RSET rset;  /* ptr to the rset this FD is opened to */
45     void *priv; /* private parameters for this type */
46     RSFD next;  /* to keep lists of used/free rsfd's */
47 };
48
49
50 struct rset_control
51 {
52     char *desc; /* text description of set type (for debugging) */
53 /* RSET rs_something_create(const struct rset_control *sel, ...); */
54     void (*f_delete)(RSET ct);
55     RSFD (*f_open)(RSET ct, int wflag);
56     void (*f_close)(RSFD rfd);
57     int (*f_forward)(RSFD rfd, void *buf, const void *untilbuf);
58     void (*f_pos)(RSFD rfd, double *current, double *total);
59        /* returns -1,-1 if pos function not implemented for this type */
60     int (*f_read)(RSFD rfd, void *buf);
61     int (*f_write)(RSFD rfd, const void *buf);
62 };
63
64 int rset_default_forward(RSFD rfd, void *buf, 
65                      const void *untilbuf);
66
67 struct key_control {
68     int key_size;
69     int scope;  /* default for what level we operate (book/chapter/verse) on*/
70                 /* usual sysno/seqno is 2 */
71     int (*cmp) (const void *p1, const void *p2);
72     void (*key_logdump_txt) (int logmask, const void *p, const char *txt);
73     zint (*getseq)(const void *p);
74       /* FIXME - Should not need a getseq, it won't make much sense with */
75       /* higher-order keys. Use a (generalized) cmp instead, or something */
76     /* FIXME - decode and encode, and lots of other stuff */
77 };
78
79 typedef struct rset
80 {
81     const struct rset_control *control;
82     const struct key_control *keycontrol;
83     int  count;  /* reference count */
84     void *priv;  /* stuff private to the given type of rset */
85     NMEM nmem;    /* nibble memory for various allocs */
86     char my_nmem; /* Should the nmem be destroyed with the rset?  */
87                   /* 1 if created with it, 0 if passed from above */
88     RSFD free_list; /* all rfd's allocated but not currently in use */
89     int scope;    /* On what level do we count hits and compare them? */
90 } rset;
91 /* rset is a "virtual base class", which will never exist on its own 
92  * all instances are rsets of some specific type, like rsisamb, or rsbool
93  * They keep their own stuff behind the priv pointer.  */
94
95 /* On the old sysno-seqno type isams, the scope was hard-coded to be 2.
96  * This means that we count hits on the sysno level, and when matching an
97  * 'and', we consider it a match if both term occur within the same sysno.
98  * In more complex isams we can specify on what level we wish to do the
99  * matching and counting of hits. For example, we can have book / chapter /
100  * verse, and a seqno. Scope 2 means then "give me all verses that match",
101  * 3 would be chapters, 4 books. 
102  * The resolution tells how much of the occurences we need to return. If we 
103  * are doing some sort of proximity, we need to get the seqnos of all
104  * occurences, whereas if we are only counting hits, we do not need anything
105  * below the scope. Again 1 is seqnos, 2 sysnos (or verses), 3 books, etc.
106  */
107 /* FIXME - Add a resolution, to decide on what level we want to return */
108 /* hits. That can well be below scope, if we need to get seqnos for prox */
109 /* or suchlike... */
110
111 RSFD rfd_create_base(RSET rs);
112 void rfd_delete_base(RSFD rfd);
113
114 RSET rset_create_base(const struct rset_control *sel, 
115                       NMEM nmem,
116                       const struct key_control *kcontrol,
117                       int scope );
118 void rset_delete(RSET rs);
119 RSET rset_dup (RSET rs);
120
121
122 #define RSETF_READ       0
123 #define RSETF_WRITE      1
124 /* RSFD rset_open(RSET rs, int wflag); */
125 #define rset_open(rs, wflag) (*(rs)->control->f_open)((rs), (wflag))
126
127 /* void rset_close(RSFD rfd); */
128 #define rset_close(rfd) (*(rfd)->rset->control->f_close)(rfd)
129
130 /* int rset_forward(RSFD rfd, void *buf, void *untilbuf); */
131 #define rset_forward(rfd, buf, untilbuf) \
132     (*(rfd)->rset->control->f_forward)((rfd),(buf),(untilbuf))
133
134 /* int rset_pos(RSFD fd, double *current, double *total); */
135 #define rset_pos(rfd,cur,tot) \
136     (*(rfd)->rset->control->f_pos)( (rfd),(cur),(tot))
137
138 /* int rset_read(RSFD rfd, void *buf); */
139 #define rset_read(rfd, buf) (*(rfd)->rset->control->f_read)((rfd), (buf))
140
141 /* int rset_write(RSFD rfd, const void *buf); */
142 #define rset_write(rfd, buf) (*(rfd)->rset->control->f_write)((rfd), (buf))
143
144 /* int rset_type (RSET) */
145 #define rset_type(rs) ((rs)->control->desc)
146
147 RSET rstemp_create( NMEM nmem, const struct key_control *kcontrol,
148                     int scope, 
149                     const char *temp_path);
150
151 RSET rsnull_create(NMEM nmem, const struct key_control *kcontrol);
152
153 RSET rsbool_create_and( NMEM nmem, const struct key_control *kcontrol,
154                         int scope, 
155                         RSET rset_l, RSET rset_r);
156
157 RSET rsbool_create_or ( NMEM nmem, const struct key_control *kcontrol,
158                         int scope,
159                         RSET rset_l, RSET rset_r);
160
161 RSET rsbool_create_not( NMEM nmem, const struct key_control *kcontrol,
162                         int scope,
163                         RSET rset_l, RSET rset_r);
164
165 RSET rsbetween_create(  NMEM nmem, const struct key_control *kcontrol,
166                         int scope, 
167                         RSET rset_l, RSET rset_m, RSET rset_r, 
168                         RSET rset_attr);
169
170 RSET rsmultior_create(  NMEM nmem, const struct key_control *kcontrol,
171                         int scope, 
172                         int no_rsets, RSET* rsets);
173
174 RSET rsmultiand_create( NMEM nmem, const struct key_control *kcontrol,
175                         int scope, 
176                         int no_rsets, RSET* rsets);
177
178 RSET rsprox_create( NMEM nmem, const struct key_control *kcontrol,
179                         int scope, 
180                     int rset_no, RSET *rset,
181                     int ordered, int exclusion,
182                     int relation, int distance);
183
184 RSET rsisamb_create( NMEM nmem, const struct key_control *kcontrol,
185                         int scope, 
186                      ISAMB is, ISAMB_P pos);
187
188 RSET rsisamc_create( NMEM nmem, const struct key_control *kcontrol,
189                         int scope, 
190                      ISAMC is, ISAMC_P pos);
191
192 RSET rsisams_create( NMEM nmem, const struct key_control *kcontrol,
193                         int scope,
194                      ISAMS is, ISAMS_P pos);
195
196
197
198 #ifdef __cplusplus
199 }
200 #endif
201
202 #endif