1 |
dpavlin |
237 |
/* |
2 |
|
|
openisis - an open implementation of the CDS/ISIS database |
3 |
|
|
Version 0.8.x (patchlevel see file Version) |
4 |
|
|
Copyright (C) 2001-2003 by Erik Grziwotz, erik@openisis.org |
5 |
|
|
|
6 |
|
|
This library is free software; you can redistribute it and/or |
7 |
|
|
modify it under the terms of the GNU Lesser General Public |
8 |
|
|
License as published by the Free Software Foundation; either |
9 |
|
|
version 2.1 of the License, or (at your option) any later version. |
10 |
|
|
|
11 |
|
|
This library is distributed in the hope that it will be useful, |
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
|
Lesser General Public License for more details. |
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU Lesser General Public |
17 |
|
|
License along with this library; if not, write to the Free Software |
18 |
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
|
20 |
|
|
see README for more information |
21 |
|
|
EOH */ |
22 |
|
|
#ifndef LDB_H |
23 |
|
|
|
24 |
|
|
/* |
25 |
|
|
$Id: ldb.h,v 1.19 2003/04/08 00:20:52 kripke Exp $ |
26 |
|
|
package interface of the general db access functions. |
27 |
|
|
*/ |
28 |
|
|
|
29 |
|
|
#include "luti.h" |
30 |
|
|
#include "lll.h" |
31 |
|
|
|
32 |
|
|
/* #define LDB_MAGIC 0x0FE91515 read OPENISIS */ |
33 |
|
|
|
34 |
|
|
|
35 |
|
|
enum { /* MFR members */ |
36 |
|
|
LMFR_MFN = 1, /* the rowid */ |
37 |
|
|
LMFR_RECL, /* total external length (even), negative for locked record */ |
38 |
|
|
LMFR_BWB, /* block of rec's previous version */ |
39 |
|
|
LMFR_BWP, /* pos of " */ |
40 |
|
|
LMFR_BASE, /* offset of contents area */ |
41 |
|
|
LMFR_NVF, /* number of fields */ |
42 |
|
|
LMFR_STAT, /* state, if != 0, about to be deleted */ |
43 |
|
|
LMFR__FL, /* offset of repeated part */ |
44 |
|
|
LMFR_TAG = 0, |
45 |
|
|
LMFR_POS, |
46 |
|
|
LMFR_LEN, |
47 |
|
|
LMFR__RL /* length of repeated part */ |
48 |
|
|
}; |
49 |
|
|
|
50 |
|
|
|
51 |
|
|
/** |
52 |
|
|
read a raw isis record by rowid. |
53 |
|
|
the memory must be freed after usage. |
54 |
|
|
*/ |
55 |
|
|
extern int *ldb_readRec ( int db, int rowid ); |
56 |
|
|
|
57 |
|
|
|
58 |
|
|
/** |
59 |
|
|
numerical type for a records file position. |
60 |
|
|
To support large DBs, this may be lll. |
61 |
|
|
*/ |
62 |
|
|
typedef int lxref; |
63 |
|
|
|
64 |
|
|
|
65 |
|
|
/** |
66 |
|
|
read a raw isis record by xref. |
67 |
|
|
the memory must be freed after usage. |
68 |
|
|
*/ |
69 |
|
|
extern int *ldb_readRecAtOff ( int dbid, lxref off, int *nxtoff ); |
70 |
|
|
|
71 |
|
|
|
72 |
|
|
|
73 |
|
|
|
74 |
|
|
/* |
75 |
|
|
** ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
76 |
|
|
** detailed search structures and functions |
77 |
|
|
** |
78 |
|
|
** ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
79 |
|
|
*/ |
80 |
|
|
|
81 |
|
|
enum { |
82 |
|
|
LDB_MAX_KEYLEN = 31, /* actually, it's 30 for isis-1 */ |
83 |
|
|
LDB_TERMBUF = 128, /* ints */ |
84 |
|
|
LDB_INDEXES = 2 |
85 |
|
|
}; |
86 |
|
|
|
87 |
|
|
|
88 |
|
|
/** |
89 |
|
|
the isis-1 posting is an 64bit number. |
90 |
|
|
In the file it's in big endian order, to allow ordering using memcmp. |
91 |
|
|
In the LdbP we have native order to use native 64bit. |
92 |
|
|
Until we need more bits for postings, we may use the 64bit type |
93 |
|
|
provided by gcc and some other compilers. |
94 |
|
|
|
95 |
|
|
the 8 bytes are: highest 3 for the rowid, then 2 tag, then 3 pos. |
96 |
|
|
the 3 pos bytes in turn are 1 byte for the occurence |
97 |
|
|
and 2 bytes for the word count. |
98 |
|
|
(e.g. value 2<<16 | 7 if term was found in the 7th word of |
99 |
|
|
the 2nd occurence of field 'tag'). |
100 |
|
|
we usually don't care, since for a near condition we always |
101 |
|
|
want a small distance w/in the same occurence which may be |
102 |
|
|
conveniently checked by the difference of 3 byte pos values. |
103 |
|
|
|
104 |
|
|
BUT NOTE: ... unfortunately we DO NEED one more bit for marking |
105 |
|
|
postings during AND operations. we abuse the highest bit of the |
106 |
|
|
word counter, since it's for sure useless for any reasonable |
107 |
|
|
distance check. |
108 |
|
|
*** BE CAREFUL WHEN COMPARING POSTINGS DURING "AND" OP *** |
109 |
|
|
use the LDBP_xxM macros below. |
110 |
|
|
*/ |
111 |
|
|
typedef union { |
112 |
|
|
char bytes[8]; |
113 |
|
|
lll val; |
114 |
|
|
} LdbP; |
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
/* all macros operate on pointers */ |
119 |
|
|
/* access parts */ |
120 |
|
|
#define LDBP_ROW( p ) (0xffffffL & (int)((p)->val >> 40)) |
121 |
|
|
#define LDBP_TAG( p ) ( 0xffffL & (int)((p)->val >> 24)) |
122 |
|
|
#define LDBP_POS( p ) (0xff7fffL & (int)((p)->val)) |
123 |
|
|
#define LDBP_MARK( p ) ( 0x8000 & (int)((p)->val)) |
124 |
|
|
|
125 |
|
|
#define LDBP_SETMARK( p ) ((p)->val |= LLL( 0x8000)) |
126 |
|
|
#define LDBP_CLRMARK( p ) ((p)->val &= LLL(0xffffffffffff7fff)) |
127 |
|
|
/* value w/o the mark bit */ |
128 |
|
|
#define LDBP_IGNMARK( p ) ((p)->val & LLL(0xffffffffffff7fff)) |
129 |
|
|
|
130 |
|
|
/* compare according to rowid, tag, pos */ |
131 |
|
|
#define LDBP_EQ( a, b ) ((a)->val == (b)->val) |
132 |
|
|
#define LDBP_GT( a, b ) ((a)->val > (b)->val) |
133 |
|
|
/* compare IGNORING MARK according to rowid, tag, pos */ |
134 |
|
|
#define LDBP_EQM( a, b ) (LDBP_IGNMARK(a) == LDBP_IGNMARK(b)) |
135 |
|
|
#define LDBP_GTM( a, b ) (LDBP_IGNMARK(a) > LDBP_IGNMARK(b)) |
136 |
|
|
|
137 |
|
|
/* manipulation: set bottom / top for row of given posting */ |
138 |
|
|
#define LDBP_SETROWBOT( d, s ) ((d)->val = (s)->val & LLL(0xffffff0000000000)) |
139 |
|
|
#define LDBP_SETROWTOP( d, s ) ((d)->val = (s)->val | LLL( 0xffffffffff)) |
140 |
|
|
|
141 |
|
|
|
142 |
|
|
/** |
143 |
|
|
postings come in arrays with some header. |
144 |
|
|
The standard structure gives a 8k buffer, |
145 |
|
|
but member len may give other actual length. |
146 |
|
|
*/ |
147 |
|
|
typedef struct { |
148 |
|
|
short mode; /* in: merge flags */ |
149 |
|
|
short near; /* in: near distance; in OR mode: collect pos info */ |
150 |
|
|
int tag; /* in: tag, to which postings are restricted */ |
151 |
|
|
int skp; /* in: ignore mfns < skp */ |
152 |
|
|
int len; /* in: length (# of postings) of buffer (if 0 : default length) */ |
153 |
|
|
int fil; /* io: number of postings actually used */ |
154 |
|
|
int cut; /* io: min mfn ignored due to buffer length */ |
155 |
|
|
LdbP p[OPENISIS_SETLEN]; |
156 |
|
|
/** |
157 |
|
|
8 bytes as in IFP file: mfn[3],tag[2],occ[1],cnt[2] |
158 |
|
|
highest bit of cnt (1LL<<15) is used as mark |
159 |
|
|
*/ |
160 |
|
|
} LdbPost; |
161 |
|
|
|
162 |
|
|
enum { |
163 |
|
|
LDB_OR, |
164 |
|
|
LDB_AND, |
165 |
|
|
LDB_NOT, /* like AND, but keep unmarked postings */ |
166 |
|
|
LDB_PFX = 4, /* prefix match */ |
167 |
|
|
LDB_KEEPMARKS = 8 /* do not compact after AND/NOT */ |
168 |
|
|
}; |
169 |
|
|
|
170 |
|
|
enum { |
171 |
|
|
LDB_NEAR_F = 0x7fff, /* the (F): same occurence of field */ |
172 |
|
|
LDB_NEAR_G = -0x8000 /* the (G): same field */ |
173 |
|
|
}; |
174 |
|
|
|
175 |
|
|
/** |
176 |
|
|
*/ |
177 |
|
|
extern int ldb_search ( int db, const char *key, LdbPost *post, |
178 |
|
|
OpenIsisRec *rec ); |
179 |
|
|
|
180 |
|
|
|
181 |
|
|
extern int ldb_p2s ( OpenIsisSet *set, LdbPost *post ); |
182 |
|
|
|
183 |
|
|
extern Db* ldb_getdb (int dbid); |
184 |
|
|
|
185 |
|
|
#define LDB_H |
186 |
|
|
#endif /* LDB_H */ |