2 * Copyright (C) 1994-1996, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.19 1996-12-11 12:08:00 adam
8 * Added better compression.
10 * Revision 1.18 1996/10/29 14:09:44 adam
11 * Use of cisam system - enabled if setting isamc is 1.
13 * Revision 1.17 1996/06/04 10:18:58 adam
14 * Minor changes - removed include of ctype.h.
16 * Revision 1.16 1996/05/13 14:23:05 adam
17 * Work on compaction of set/use bytes in dictionary.
19 * Revision 1.15 1995/11/20 16:59:46 adam
20 * New update method: the 'old' keys are saved for each records.
22 * Revision 1.14 1995/10/30 15:08:08 adam
25 * Revision 1.13 1995/10/27 14:00:11 adam
26 * Implemented detection of database availability.
28 * Revision 1.12 1995/10/17 18:02:08 adam
29 * New feature: databases. Implemented as prefix to words in dictionary.
31 * Revision 1.11 1995/10/06 16:33:37 adam
32 * Use attribute mappings.
34 * Revision 1.10 1995/09/29 14:01:41 adam
37 * Revision 1.9 1995/09/28 12:10:32 adam
38 * Bug fixes. Field prefix used in queries.
40 * Revision 1.8 1995/09/28 09:19:42 adam
41 * xfree/xmalloc used everywhere.
42 * Extract/retrieve method seems to work for text records.
44 * Revision 1.7 1995/09/27 12:22:28 adam
45 * More work on extract in record control.
46 * Field name is not in isam keys but in prefix in dictionary words.
48 * Revision 1.6 1995/09/14 07:48:23 adam
49 * Record control management.
51 * Revision 1.5 1995/09/11 13:09:34 adam
52 * More work on relevance feedback.
54 * Revision 1.4 1995/09/08 14:52:27 adam
55 * Minor changes. Dictionary is lower case now.
57 * Revision 1.3 1995/09/07 13:58:36 adam
58 * New parameter: result-set file descriptor (RSFD) to support multiple
59 * positions within the same result-set.
60 * Boolean operators: and, or, not implemented.
61 * Result-set references.
63 * Revision 1.2 1995/09/06 16:11:17 adam
64 * Option: only one word key per file.
66 * Revision 1.1 1995/09/04 09:10:36 adam
67 * More work on index add/del/update.
68 * Merge sort implemented.
69 * Initial work on z39 server.
80 void key_logdump (int logmask, const void *p)
84 memcpy (&key, p, sizeof(key));
85 logf (logmask, "%7d s=%-4d", key.sysno, key.seqno);
88 int key_compare (const void *p1, const void *p2)
91 memcpy (&i1, p1, sizeof(i1));
92 memcpy (&i2, p2, sizeof(i2));
93 if (i1.sysno != i2.sysno)
95 if (i1.sysno > i2.sysno)
100 #if IT_KEY_HAVE_SEQNO
101 if (i1.seqno != i2.seqno)
103 if (i1.seqno > i2.seqno)
109 if (i1.freq != i2.freq)
111 if (i1.freq > i2.freq)
120 int key_qsort_compare (const void *p1, const void *p2)
124 char *cp1 = *(char **) p1;
125 char *cp2 = *(char **) p2;
127 if ((r = strcmp (cp1, cp2)))
130 if ((r = key_compare (cp1+l+1, cp2+l+1)))
132 return cp1[l] - cp2[l];
135 struct iscz1_code_info {
139 static void *iscz1_code_start (int mode)
141 struct iscz1_code_info *p = xmalloc (sizeof(*p));
147 static void iscz1_code_stop (int mode, void *p)
152 void iscz1_encode_int (unsigned d, char **dst)
154 unsigned char *bp = (unsigned char*) *dst;
163 else if (d <= 4194303)
165 *bp++ = 128 + (d>>16);
166 *bp++ = (d>>8) & 255;
171 *bp++ = 192 + (d>>24);
172 *bp++ = (d>>16) & 255;
173 *bp++ = (d>>8) & 255;
179 int iscz1_decode_int (unsigned char **src)
181 unsigned c = *(*src)++;
187 return ((c & 63) << 8) + *(*src)++;
189 c = ((c & 63) << 8) + *(*src)++;
190 c = (c << 8) + *(*src)++;
193 c = ((c & 63) << 8) + *(*src)++;
194 c = (c << 8) + *(*src)++;
195 c = (c << 8) + *(*src)++;
199 static void iscz1_code_item (int mode, void *vp, char **dst, char **src)
201 struct iscz1_code_info *p = vp;
205 if (mode == ISAMC_ENCODE)
207 memcpy (&tkey, *src, sizeof(struct it_key));
208 d = tkey.sysno - p->key.sysno;
211 iscz1_encode_int (2*tkey.seqno + 1, dst);
212 iscz1_encode_int (d, dst);
214 p->key.seqno = tkey.seqno;
218 iscz1_encode_int (2*(tkey.seqno - p->key.seqno), dst);
219 p->key.seqno = tkey.seqno;
221 (*src) += sizeof(struct it_key);
225 d = iscz1_decode_int ((unsigned char **) src);
229 p->key.sysno += iscz1_decode_int ((unsigned char **) src);
232 p->key.seqno += d>>1;
233 memcpy (*dst, &p->key, sizeof(struct it_key));
234 (*dst) += sizeof(struct it_key);
238 static void iscz1_code_item (int mode, void *vp, char **dst, char **src)
240 struct iscz1_code_info *p = vp;
244 if (mode == ISAMC_ENCODE)
246 memcpy (&tkey, *src, sizeof(struct it_key));
247 d = tkey.sysno - p->key.sysno;
248 iscz1_encode_int (d, dst);
251 p->key.sysno = tkey.sysno;
254 iscz1_encode_int (tkey.seqno - p->key.seqno, dst);
255 p->key.seqno = tkey.seqno;
256 (*src) += sizeof(struct it_key);
260 d = iscz1_decode_int ((unsigned char **) src);
266 d = iscz1_decode_int ((unsigned char **) src);
268 memcpy (*dst, &p->key, sizeof(struct it_key));
269 (*dst) += sizeof(struct it_key);
274 ISAMC_M key_isamc_m (void)
276 static ISAMC_M me = NULL;
281 me = isc_getmethod ();
283 me->compare_item = key_compare;
285 me->code_start = iscz1_code_start;
286 me->code_item = iscz1_code_item;
287 me->code_stop = iscz1_code_stop;
289 me->debug = atoi(res_get_def (common_resource, "isamcDebug", "0"));
291 logf (LOG_LOG, "ISAMC system active");