e72d3344a2eb4f4569caa3119b5b42df812ca812
[idzebra-moved-to-github.git] / isamc / merge-d.c
1 /* $Id: merge-d.c,v 1.29 2002-11-26 22:18:34 adam 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
26 #define NEW_ISAM_D 1  /* not yet ready to delete the old one! */
27
28 #include <stdlib.h>
29 #include <assert.h>
30 #include <string.h>
31 #include <stdio.h>
32 #include <yaz/log.h>
33 #include "../index/index.h"
34 #include "isamd-p.h"
35
36
37 struct ISAMD_DIFF_s {
38   int diffidx;
39   int maxidx;
40   struct it_key key;
41   void *decodeData;
42   int mode;
43   int difftype;  
44 };
45
46 #define DT_NONE 0 /* no diff, marks end of sequence */
47 #define DT_DIFF 1 /* ordinarry diff */
48 #define DT_MAIN 2 /* main data */
49 #define DT_INPU 3 /* input data to be merged */
50 #define DT_DONE 4 /* done with all input here */
51
52
53
54 /***************************************************************
55  * Input preprocess filter
56  ***************************************************************/
57
58
59 #define FILTER_NOTYET -1  /* no data read in yet, to be done */
60
61 struct ISAMD_FILTER_s {
62   ISAMD_I data;          /* where the data comes from */
63   ISAMD is;              /* for debug flags */
64   struct it_key k1;      /* the next item to be returned */
65   int           m1;      /* mode for k1 */
66   int           r1;      /* result for read of k1, or NOTYET */
67   struct it_key k2;      /* the one after that */
68   int           m2;
69   int           r2;
70 };
71
72 typedef struct ISAMD_FILTER_s *FILTER;
73
74
75 void filter_fill(FILTER F)
76 {
77   while ( (F->r1 == FILTER_NOTYET) || (F->r2 == FILTER_NOTYET) )
78   {
79      if (F->r1==FILTER_NOTYET) 
80      { /* move data forward in the filter */
81         F->k1 = F->k2;
82         F->m1 = F->m2;
83         F->r1 = F->r2;
84         if ( 0 != F->r1 ) /* not eof */
85           F->r2 = FILTER_NOTYET; /* say we want more */
86         if (F->is->method->debug > 9)  
87           logf(LOG_LOG,"filt_fill: shift %d.%d m=%d r=%d",
88              F->k1.sysno, 
89              F->k1.seqno, 
90              F->m1, F->r1);
91      }
92      if (F->r2==FILTER_NOTYET)
93      { /* read new bottom value */
94         char *k_ptr = (char*) &F->k2;
95         F->r2 = (F->data->read_item)(F->data->clientData, &k_ptr, &F->m2); 
96         if (F->is->method->debug > 9)
97           logf(LOG_LOG,"filt_fill: read %d.%d m=%d r=%d",
98              F->k2.sysno, F->k2.seqno, F->m2, F->r2);
99      }  
100      if ( (F->k1.sysno == F->k2.sysno) && 
101           (F->k1.seqno == F->k2.seqno) &&
102           (F->m1 != F->m2) &&
103           (F->r1 >0 ) && (F->r2 >0) )
104      { /* del-ins pair of same key (not eof) , ignore both */
105        if (F->is->method->debug > 9)
106          logf(LOG_LOG,"filt_fill: skipped %d.%d m=%d/%d r=%d/%d",
107             F->k1.sysno, F->k1.seqno, 
108             F->m1,F->m2, F->r1,F->r2);
109        F->r1 = FILTER_NOTYET;
110        F->r2 = FILTER_NOTYET;
111      }
112   } /* while */
113 } /* filter_fill */
114
115
116 FILTER filter_open( ISAMD is, ISAMD_I data )
117 {
118   FILTER F = (FILTER) xmalloc(sizeof(struct ISAMD_FILTER_s));
119   F->is = is;
120   F->data = data;
121   F->k1.sysno=0;
122   F->k1.seqno=0;
123   F->k2=F->k1; 
124   F->m1 = F->m2 = 0;
125   F->r1 = F->r2 = FILTER_NOTYET;
126   filter_fill(F);
127   return F;
128 }
129
130 static void filter_close (FILTER F)
131 {
132   xfree(F);
133 }
134
135 static int filter_read( FILTER F, 
136                         struct it_key *k,
137                         int *mode)
138 {
139   int res;
140   filter_fill(F);
141   if (F->is->method->debug > 9)
142     logf(LOG_LOG,"filt_read: reading %d.%d m=%d r=%d",
143        F->k1.sysno, F->k1.seqno, F->m1, F->r1);
144   res  = F->r1;
145   if(res) 
146   {
147     *k = F->k1;
148     *mode= F->m1;
149   }
150   F->r1 = FILTER_NOTYET;
151   return res;
152 }
153
154 static int filter_isempty(FILTER F)
155 {
156   return ( (0 == F->r1) && (0 == F->r2)) ;
157 }
158
159 static int filter_only_one(FILTER F)
160 {
161   return ( (0 != F->r1) && (0 == F->r2));
162 }
163
164 /* We may need backfilling, if we read a lonely key to make */
165 /* a singleton, but its bitw will not fit in. Then we need to */
166 /* process it normally, which means reading it again. So we  */
167 /* need to unread it first. Luckily the filter is empty at that */
168 /* point */
169 static void filter_backfill(FILTER F, struct it_key *k, int mode)
170 {
171   assert(F->r1 == FILTER_NOTYET ); /* not overwriting data! */
172   F->k1=*k;
173   F->m1=mode;
174   F->r1=1; /* ok read */
175 }
176
177
178 /***************************************************************
179  * Singleton encoding
180  ***************************************************************/
181 /* When there is only a single item, we don't allocate a block
182  * for it, but code it in the directory entry directly, if it
183  * fits.
184  */
185
186 #define DEC_SYSBITS 15
187 #define DEC_SEQBITS 15
188 #define DEC_MASK(n) ((1<<(n))-1)
189
190 #define SINGLETON_BIT (1<<(DEC_SYSBITS+DEC_SEQBITS+1))
191
192 int is_singleton(ISAMD_P ipos)
193 {
194   return 0; /* no singletons any more */
195   return ( ipos != 0 ) && ( ipos & SINGLETON_BIT );
196 }
197
198
199 int singleton_encode(struct it_key *k)
200 /* encodes the key into one int. If it does not fit, returns 0 */
201 {
202   return 0; /* no more singletons */
203   if ( (k->sysno & DEC_MASK(DEC_SYSBITS) ) != k->sysno )
204     return 0;  /* no room dor sysno */
205   if ( (k->seqno & DEC_MASK(DEC_SYSBITS) ) != k->seqno )
206     return 0;  /* no room dor sysno */
207   return (k->sysno | (k->seqno << DEC_SYSBITS) ) | SINGLETON_BIT;
208 }
209  
210 void singleton_decode (int code, struct it_key *k)
211 {
212   assert (code & SINGLETON_BIT);
213   k->sysno = code & DEC_MASK(DEC_SYSBITS);
214   code = code >> DEC_SYSBITS; 
215   k->seqno = code & DEC_MASK(DEC_SEQBITS);
216
217  
218  
219 /***************************************************************
220  * General support routines
221  ***************************************************************/
222
223
224
225 static char *hexdump(unsigned char *p, int len, char *buff) {
226   static char localbuff[128];
227   char bytebuff[8];
228   if (!buff) buff=localbuff;
229   *buff='\0';
230   while (len--) {
231     sprintf(bytebuff,"%02x",*p);
232     p++;
233     strcat(buff,bytebuff);
234     if (len) strcat(buff,",");
235   }
236   return buff;
237 }
238
239
240
241 static void isamd_reduceblock(ISAMD_PP pp)
242 /* takes a large block, and reduces its category if possible */
243 /* Presumably the first block in an isam-list */
244 {
245    if (pp->pos)
246       return; /* existing block, do not touch */
247       /* TODO: Probably we may touch anyway? */
248    if (pp->is->method->debug > 5)  
249      logf(LOG_LOG,"isamd_reduce: start p=%d c=%d sz=%d",
250        pp->pos, pp->cat, pp->size); 
251    while ( ( pp->cat > 0 ) && (!pp->next) && 
252            (pp->offset < pp->is->method->filecat[pp->cat-1].bsize ) )
253       pp->cat--;
254    pp->pos = isamd_alloc_block(pp->is, pp->cat);
255    if (pp->is->method->debug > 5) 
256      logf(LOG_LOG,"isamd_reduce:  got  p=%d c=%d sz=%d",
257        pp->pos, pp->cat, pp->size);    
258 } /* reduceblock */
259
260
261 static int save_first_pp ( ISAMD_PP firstpp)
262 {
263    isamd_buildfirstblock(firstpp);
264    isamd_write_block(firstpp->is,firstpp->cat,firstpp->pos,firstpp->buf);
265    return isamd_addr(firstpp->pos,firstpp->cat);
266 }
267
268  
269 static void save_last_pp (ISAMD_PP pp)
270 {
271    pp->next = 0;/* just to be sure */
272    isamd_buildlaterblock(pp);
273    isamd_write_block(pp->is,pp->cat,pp->pos,pp->buf);
274 }
275
276 #ifdef UNUSED
277 static int save_both_pps (ISAMD_PP firstpp, ISAMD_PP pp)
278 {
279    /* order of things: Better to save firstpp first, if there are just two */
280    /* blocks, but last if there are blocks in between, as these have already */
281    /* been saved... optimise later (that's why this is in its own func...*/
282    int retval = save_first_pp(firstpp);
283    if (firstpp!=pp){ 
284       save_last_pp(pp);
285       isamd_pp_close(pp);
286    }
287    isamd_pp_close(firstpp);
288    return retval;
289 } /* save_both_pps */
290 #endif
291
292
293
294 /***************************************************************
295  * Diffblock handling
296  ***************************************************************/
297
298 void isamd_free_diffs(ISAMD_PP pp)
299 {
300   int i;
301   if (pp->is->method->debug > 5)
302      logf(LOG_LOG,"isamd_free_diffs: pp=%p di=%p", pp, pp->diffinfo);
303   if (!pp->diffinfo) 
304     return;
305   for (i=0;pp->diffinfo[i].difftype!=DT_NONE;i++) 
306       if(pp->diffinfo[i].decodeData)
307       {
308           if (pp->is->method->debug > 8)
309              logf(LOG_LOG,"isamd_free_diffs [%d]=%p",i, 
310                            pp->diffinfo[i].decodeData);
311           (*pp->is->method->code_stop)(ISAMD_DECODE,pp->diffinfo[i].decodeData);
312       } 
313   xfree(pp->diffinfo);
314   if (pp->diffbuf != pp->buf)
315     xfree (pp->diffbuf);  
316   pp->diffbuf=0;
317   pp->diffinfo=0;
318 } /* isamd_free_diffs */
319
320
321 static void getDiffInfo(ISAMD_PP pp )
322 { /* builds the diff info structures from a diffblock */
323    int maxinfos = pp->is->method->filecat[pp->cat].bsize / 5 +2;
324     /* Each diff takes at least 5 bytes. Probably more, but this is safe */
325    int i=1;  /* [0] is used for the main data, [n+1] for merge inputs */
326    int diffsz= maxinfos * sizeof(struct ISAMD_DIFF_s);
327    int maxsz = pp->is->method->filecat[pp->is->max_cat].bsize;
328    int diffidx = ISAMD_BLOCK_OFFSET_1;
329
330    pp->diffinfo = xmalloc( diffsz ); 
331    pp->offset = pp->size+1; /* used this block up */
332    memset(pp->diffinfo,'\0',diffsz);
333    if (pp->is->method->debug > 5)   
334       logf(LOG_LOG,"isamd_getDiffInfo: %d=%d:%d->%d, ix=%d mx=%d",
335          isamd_addr(pp->pos, pp->cat), pp->cat, pp->pos, pp->next,
336          diffidx,maxinfos);
337    
338    /* duplicate the buffer for diffs */
339    /* (so that we can read the next real buffer(s) */
340    assert(0==pp->diffbuf);
341    pp->diffbuf=xmalloc(maxsz);
342    memcpy(pp->diffbuf, pp->buf, maxsz);
343    
344    pp->diffinfo[0].maxidx=-1; /* mark as special */
345    pp->diffinfo[0].difftype=DT_MAIN;
346
347    while (i<maxinfos) 
348    {  
349       if ( diffidx+sizeof(int) > pp->is->method->filecat[pp->cat].bsize )
350       {
351          if (pp->is->method->debug > 5)
352            logf(LOG_LOG,"isamd_getDiffInfo:Near end (no room for len) at ix=%d n=%d",
353                diffidx, i);
354          return; /* whole block done */
355       }
356       memcpy( &pp->diffinfo[i].maxidx, &pp->diffbuf[diffidx], sizeof(int) );
357       pp->diffinfo[i].difftype=DT_DIFF;
358       if (pp->is->method->debug > 5)
359         logf(LOG_LOG,"isamd_getDiffInfo: max=%d ix=%d dbuf=%p",
360           pp->diffinfo[i].maxidx, diffidx, pp->diffbuf);
361
362       if ( (pp->is->method->debug > 0) &&
363          (pp->diffinfo[i].maxidx > pp->is->method->filecat[pp->cat].bsize) )
364       { 
365          logf(LOG_LOG,"Bad MaxIx!!! %s:%d: diffidx=%d", 
366                        __FILE__,__LINE__, diffidx);
367          logf(LOG_LOG,"i=%d maxix=%d bsz=%d", i, pp->diffinfo[i].maxidx,
368                        pp->is->method->filecat[pp->cat].bsize);
369          logf(LOG_LOG,"pp=%d=%d:%d  pp->nx=%d=%d:%d",
370                        isamd_addr(pp->pos,pp->cat), pp->pos, pp->cat,
371                        pp->next, isamd_type(pp->next), isamd_block(pp->next) );                      
372       }
373       assert(pp->diffinfo[i].maxidx <= pp->is->method->filecat[pp->cat].bsize+1);
374
375       if (0==pp->diffinfo[i].maxidx)
376       {
377          if (pp->is->method->debug > 5)  /* !!! 4 */
378            logf(LOG_LOG,"isamd_getDiffInfo:End mark at ix=%d n=%d",
379                diffidx, i);
380          return; /* end marker */
381       }
382       diffidx += sizeof(int);
383       pp->diffinfo[i].decodeData = (*pp->is->method->code_start)(ISAMD_DECODE);
384       pp->diffinfo[i].diffidx = diffidx;
385       if (pp->is->method->debug > 5)
386         logf(LOG_LOG,"isamd_getDiff[%d]:%d-%d %s",
387           i,diffidx-sizeof(int),pp->diffinfo[i].maxidx,
388           hexdump((char *)&pp->diffbuf[diffidx-4],8,0) );
389       diffidx=pp->diffinfo[i].maxidx;
390       if ( diffidx > pp->is->method->filecat[pp->cat].bsize )
391         return; /* whole block done */
392       ++i;
393    }
394    assert (!"too many diff sequences in the block");
395 }
396
397 /***************************************************************
398  * Main block operations
399  ***************************************************************/
400
401
402 static ISAMD_PP get_new_main_block( ISAMD_PP firstpp, ISAMD_PP pp)
403 {  /* allocates a new block for the main data, and links it in */
404   int newblock;
405   if (0 == firstpp->next) 
406   {  /* special case, pp not yet allocated. */
407      /*Started as largest size, that's fine */
408      pp->pos = isamd_alloc_block(pp->is,pp->cat);
409      firstpp->next = isamd_addr(pp->pos,pp->cat);
410      if (pp->is->method->debug >3) 
411         logf(LOG_LOG,"isamd_build: Alloc 1. dblock  p=%d=%d:%d",
412            isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos);
413   }
414   newblock=isamd_alloc_block(pp->is,pp->cat);
415   pp->next=isamd_addr(newblock,pp->cat);
416   isamd_buildlaterblock(pp);
417   isamd_write_block(pp->is,pp->cat,pp->pos,pp->buf);
418   if (pp->is->method->debug >3) 
419      logf(LOG_LOG,"isamd_build: Alloc nxt %d=%d:%d -> %d=%d:%d",
420         isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos,
421         isamd_addr(newblock,pp->cat), pp->cat, newblock);
422   pp->next=0;
423   pp->pos=newblock;
424   pp->size=pp->offset=ISAMD_BLOCK_OFFSET_N;  
425   return pp;
426 } /* get_new_main_block */
427
428
429 static ISAMD_PP  append_main_item(ISAMD_PP firstpp, 
430                                   ISAMD_PP pp, 
431                                   struct it_key *i_key)
432 {  /* appends one item in the main data block, allocates new if needed */
433    char *i_item= (char *) i_key;  /* same as char */
434    char *i_ptr=i_item;
435    char codebuff[128];
436    char *c_ptr = codebuff;
437    int codelen;
438    char hexbuff[64];
439
440    int maxsize = pp->is->method->filecat[pp->is->max_cat].bsize; 
441
442    c_ptr=codebuff;
443    i_ptr=i_item;
444    (*pp->is->method->code_item)(ISAMD_ENCODE, pp->decodeClientData,
445                                 &c_ptr, &i_ptr);
446    codelen = c_ptr - codebuff;
447    assert ( (codelen<128) && (codelen>0));
448    if (pp->is->method->debug >7)
449       logf(LOG_LOG,"isamd:build: coded %s nk=%d,ofs=%d-%d",
450           hexdump(codebuff, c_ptr-codebuff,hexbuff), firstpp->numKeys+1,
451           pp->offset, pp->offset+codelen);
452
453    if (pp->offset + codelen > maxsize )
454    { /* oops, block full - get a new one */
455       pp =  get_new_main_block( firstpp, pp );
456       /* reset encoging and code again */
457       (*pp->is->method->code_reset)(pp->decodeClientData);
458       c_ptr=codebuff;
459       i_ptr=i_item;
460       (*pp->is->method->code_item)(ISAMD_ENCODE, pp->decodeClientData, 
461                                    &c_ptr, &i_ptr);
462       codelen = c_ptr - codebuff;
463       assert ( (codelen<128) && (codelen>0));
464       if (pp->is->method->debug >7)
465          logf(LOG_LOG,"isamd:build: recoded into %s  (nk=%d)",
466              hexdump(codebuff, c_ptr-codebuff,hexbuff), firstpp->numKeys+1);
467    } /* block full */    
468
469    assert (pp->offset + codelen <= maxsize );
470    
471    /* write the data into pp, now we must have room */ 
472    memcpy(&(pp->buf[pp->offset]),codebuff,codelen);
473    pp->offset += codelen;
474    pp->size += codelen;
475    firstpp->numKeys++;
476    /* clear the next 4 bytes in block, to avoid confusions with diff lens */
477    /* dirty, it should not be done here, but something slips somewhere, and */
478    /* I hope this fixes it...  - Heikki */
479    codelen = pp->offset;
480    while ( (codelen < maxsize ) && (codelen <= pp->offset+4) )
481      pp->buf[codelen++] = '\0';
482    return pp;    
483 } /* append_main_item */
484
485
486 /***************************************************************
487  * Read with merge
488  ***************************************************************/
489
490 /* Reads one item and corrects for the diffs, if any */
491 /* return 1 for ok, 0 for eof */
492 int isamd_read_item_merge (
493                      ISAMD_PP pp, 
494                      char **dst,
495                      struct it_key *p_key,  /* the data item that didn't fit*/
496               /*       ISAMD_I data)  */    /* more input data comes here */
497                      FILTER filt)           /* more input data comes here */
498 {                    /* The last two args can be null for ordinary reads */
499   char *keyptr;
500   char *codeptr;
501   char *codestart;
502   int winner=0; /* which diff holds the day */
503   int i; /* looping diffs */
504   int cmp;
505   int retry=1;
506   int oldoffs;
507   int rc;
508
509   if (!pp->diffinfo)  
510   { /* first time */
511      getDiffInfo(pp);
512
513      for(i=1; pp->diffinfo[i].difftype!=DT_NONE; i++)
514        ;  /* find last diff */
515      if (p_key)  
516      {  /* we have an extra item to inject into the merge */
517        if (pp->is->method->debug >9)  /* !!!!! */
518           logf(LOG_LOG,"isamd_read_item: going to merge with %d.%d",
519                p_key->sysno, p_key->seqno);
520        pp->diffinfo[i].key = *p_key;  /* the key merge could not handle */
521        pp->diffinfo[i].mode = pp->diffinfo[i].key.seqno & 1;
522        pp->diffinfo[i].key.seqno >>= 1;
523        pp->diffinfo[i].difftype=DT_INPU;
524        if (pp->is->method->debug > 7)
525          logf(LOG_LOG,"isamd_read_item: inpu key %d sys=%d  seq=%d=2*%d+%d",
526             i, p_key->sysno,
527             pp->diffinfo[i].key.seqno*2 + pp->diffinfo[1].mode,
528             pp->diffinfo[i].key.seqno,
529             pp->diffinfo[i].mode);
530        p_key->sysno=p_key->seqno=0;  /* used it up */
531      }
532
533      if (filt)
534      { /* we have a whole input stream to inject */
535        pp->diffinfo[i].difftype=DT_INPU;
536      }
537   } /* first time */ 
538         
539   while (retry)
540
541   {
542      retry=0;     
543      winner = 0;
544      for (i=0; (!retry) && (pp->diffinfo[i].difftype); i++)
545      {
546         if (0==pp->diffinfo[i].key.sysno)
547         {/* read a new one, if possible */
548            if ((pp->diffinfo[i].difftype==DT_DIFF) &&
549              (pp->diffinfo[i].diffidx < pp->diffinfo[i].maxidx))
550            { /* a normal kind of diff */
551               oldoffs=pp->diffinfo[i].diffidx;
552               codeptr= codestart = &(pp->diffbuf[pp->diffinfo[i].diffidx]);
553               keyptr=(char *)&(pp->diffinfo[i].key);
554               (*pp->is->method->code_item)(ISAMD_DECODE,
555                     pp->diffinfo[i].decodeData, &keyptr, &codeptr);
556               pp->diffinfo[i].diffidx += codeptr-codestart;
557               pp->diffinfo[i].mode = pp->diffinfo[i].key.seqno & 1;
558               pp->diffinfo[i].key.seqno = pp->diffinfo[i].key.seqno >>1 ;
559               if (pp->is->method->debug > 9)
560                 logf(LOG_LOG,"isamd_read_item: dif[%d] at %d-%d: %s",
561                   i,oldoffs, pp->diffinfo[i].diffidx,
562                   hexdump(pp->buf+oldoffs, pp->diffinfo[i].diffidx-oldoffs,0));
563               if (pp->is->method->debug > 7)
564                 logf(LOG_LOG,"isamd_read_item: rd dif[%d] %d.%d (%x.%x)",
565                   i,
566                   pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
567                   pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno);
568            }
569            else if ( pp->diffinfo[i].difftype==DT_MAIN)
570            { /* read a main item */
571               assert(i==0);  /* main data goes before any diffs */
572               oldoffs=pp->offset;
573               keyptr=(char*) &(pp->diffinfo[0].key);
574               rc= isamd_read_main_item(pp,&keyptr);
575               if (0==rc) 
576               { /* eof */
577                  if (pp->is->method->debug > 7)
578                    logf(LOG_LOG,"isamd_read_item: eof (rc=%d) main ",
579                            rc);
580                 pp->diffinfo[i].maxidx=-1;
581                 pp->diffinfo[i].key.sysno=0;
582                 pp->diffinfo[i].key.seqno=0;
583                 pp->diffinfo[i].difftype= DT_DONE;
584               } 
585               else
586               { /* not eof */
587                  pp->diffinfo[i].mode = 1;
588                  if (pp->is->method->debug > 7)
589                    logf(LOG_LOG,"isamd_read_item: rd main %d-%d %d.%d (%x.%x) m=%d",
590                      oldoffs,pp->offset,
591                      pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
592                      pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
593                      pp->diffinfo[i].mode);
594               } /* not eof */
595            }
596            else if (pp->diffinfo[i].difftype==DT_INPU)
597            {
598               keyptr = (char *) &pp->diffinfo[i].key;
599          /*     rc = (*data->read_item)(data->clientData, &keyptr, &pp->diffinfo[i].mode); */
600               rc = filter_read(filt, &pp->diffinfo[i].key, 
601                                      &pp->diffinfo[i].mode); 
602               if (!rc) 
603               {  /* did not get it */
604                  pp->diffinfo[i].key.sysno=0;
605                  pp->diffinfo[i].maxidx=0; /* signal the end */
606                  pp->diffinfo[i].difftype=DT_DONE;
607               }
608               if (pp->is->method->debug >7)
609                  logf(LOG_LOG,"merge: read inpu m=%d %d.%d (%x.%x)",
610                     pp->diffinfo[i].mode, 
611                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
612                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno );        
613            } /* read an input item */
614         } /* read a new one */
615         
616         if (pp->is->method->debug > 8)
617           logf(LOG_LOG,"isamd_read_item: considering d%d %d.%d ix=%d mx=%d",
618                i, pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
619                   pp->diffinfo[i].diffidx,   pp->diffinfo[i].maxidx);
620             
621         if ( 0!= pp->diffinfo[i].key.sysno)
622         { /* got a key, compare */
623           if (i!=winner)
624              cmp=key_compare(&pp->diffinfo[i].key, &pp->diffinfo[winner].key);
625           else
626              cmp=-1;
627           if (0==pp->diffinfo[winner].key.sysno)
628             cmp=-1; /* end of main sequence, take all diffs */
629           if (cmp<0)
630           {
631              if (pp->is->method->debug > 8)
632                logf(LOG_LOG,"isamd_read_item: ins [%d]%d.%d < [%d]%d.%d",
633                  i,  
634                  pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
635                  winner, 
636                  pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno);
637              if (pp->diffinfo[i].mode)  /* insert diff, should always be */
638                winner = i;
639              else
640              {
641                if (pp->is->method->debug > 1)
642                  logf(LOG_LOG,"delete diff for nonexisting item");
643                assert(!"delete diff for nonexisting item");  
644                /* is an assert too steep here? Not really.*/
645              }
646           } /* earlier key */
647           else if (cmp==0)
648           {
649              if (!pp->diffinfo[i].mode) /* delete diff. should always be */
650              {
651                 if (pp->is->method->debug > 8)
652                   logf(LOG_LOG,"isamd_read_item: del %d at%d %d.%d (%x.%x)",
653                     i, winner,
654                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
655                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno);
656                 pp->diffinfo[winner].key.sysno=0; /* delete it */
657              }
658              else
659                 if (pp->is->method->debug > 2)
660                   logf(LOG_LOG,"isamd_read_item: duplicate ins %d at%d %d.%d (%x.%x)",
661                     i, winner,
662                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno,
663                     pp->diffinfo[i].key.sysno, pp->diffinfo[i].key.seqno);
664                 /* skip the insert, since we already have it in the base */
665                 /* Should we fail an assertion here??? */
666              pp->diffinfo[i].key.sysno=0; /* done with the delete */
667              retry=1; /* start all over again */
668           } /* matching key */
669           /* else it is a later key, its turn will come */
670         } /* got a key */
671      } /* for each diff */
672   } /* not retry */
673
674   if ( pp->diffinfo[winner].key.sysno)
675   {
676     if (pp->is->method->debug > 7)
677       logf(LOG_LOG,"isamd_read_item: got %d  %d.%d (%x.%x)",
678         winner,
679         pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno,
680         pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno);
681     memcpy(*dst, &pp->diffinfo[winner].key, sizeof(struct it_key) );
682     *dst += sizeof(struct it_key);
683     pp->diffinfo[winner].key.sysno=0; /* used that one up */
684     cmp= 1;
685   } 
686   else 
687   {
688     if (pp->is->method->debug > 7)
689       logf(LOG_LOG,"isamd_read_item: eof w=%d  %d.%d (%x.%x)",
690         winner,
691         pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno,
692         pp->diffinfo[winner].key.sysno, pp->diffinfo[winner].key.seqno);
693     assert(winner==0); /* if nothing found, nothing comes from a diff */
694     cmp= 0; /* eof */
695   }
696   if (cmp)
697     ++(pp->is->no_read_keys);
698   else
699     ++(pp->is->no_read_eof);
700
701   return cmp;
702    
703 } /* isamd_read_item */
704
705
706 int isamd_read_item (ISAMD_PP pp, char **dst)
707 {
708   return isamd_read_item_merge(pp,dst,0,0);
709 }
710
711
712 /***************************************************************
713  * Merge
714  ***************************************************************/
715
716 static int merge ( ISAMD_PP firstpp,      /* first pp (with diffs) */
717                    struct it_key *p_key,  /* the data item that didn't fit*/
718                    FILTER filt,           /* more input data arriving here */
719                    char *dictentry,       /* the thin in the dictionary */
720                    int dictlen)           /* and its size */
721 {
722   int diffidx;  
723   int killblk=0;
724   struct it_key r_key;
725   char * r_ptr;
726   int r_more = 1;
727   ISAMD_PP pp;
728   ISAMD_PP readpp=firstpp;
729   int retpos=0;
730   int diffcat = firstpp->cat;  /* keep the category of the diffblock even */
731                                /* if it is going to be empty now. */
732                                /* Alternative: Make it the minimal, and */
733                                /* resize later. Saves disk, but will lead */
734                                /* into bad seeks. */
735   
736   ++(readpp->is->no_merges);
737      
738   /* set up diffs as they should be for reading */
739   diffidx = ISAMD_BLOCK_OFFSET_1; 
740   
741   if (readpp->is->method->debug >4) 
742       logf(LOG_LOG,"isamd_merge: f=%d=%d:%d n=%d=%d:%d",
743         isamd_addr(firstpp->pos,firstpp->cat), firstpp->cat, firstpp->pos,
744         firstpp->next, isamd_type(firstpp->next), isamd_block(firstpp->next));  
745
746   /* release our data block. Do before reading, when pos is stable ! */
747   killblk=firstpp->pos;
748   if (killblk)
749   {
750       isamd_release_block(firstpp->is, firstpp->cat, killblk);
751       if (readpp->is->method->debug >3)   
752           logf(LOG_LOG,"isamd_merge: released old firstblock %d (%d:%d)",
753               isamd_addr(killblk,firstpp->cat), firstpp->cat, killblk );
754   }
755   
756
757   r_ptr= (char *) &r_key;
758   r_more = isamd_read_item_merge( readpp, &r_ptr, p_key, filt);
759   if (!r_more)  
760   { /* oops, all data has been deleted! what to do??? */
761     /* never mind, we have at least one more delta to add to the block */
762     /* pray that is not a delete as well... */
763     r_key.sysno = 0;
764     r_key.seqno = 0;
765      if (readpp->is->method->debug >5) 
766          logf(LOG_LOG,"isamd_merge:all data has been deleted (nk=%d) ",
767             readpp->numKeys);
768   }
769
770
771   /* set up the new blocks for simple writing */
772   /* firstpp=isamd_pp_open(readpp->is,isamd_addr(0, diffcat)); */
773   firstpp=isamd_pp_create(readpp->is, diffcat);
774   firstpp->pos=isamd_alloc_block(firstpp->is,diffcat);
775   if (readpp->is->method->debug >3)   
776       logf(LOG_LOG,"isamd_merge: allocated new firstpp %d=%d:%d",
777           isamd_addr(firstpp->pos,firstpp->cat), firstpp->cat, firstpp->pos );
778   
779   pp=isamd_pp_create(readpp->is,readpp->is->max_cat );
780   pp->offset=pp->size=ISAMD_BLOCK_OFFSET_N;
781   
782   while (r_more)
783   {
784      if (readpp->is->method->debug >6) 
785          logf(LOG_LOG,"isamd_merge: got key %d.%d",
786            r_key.sysno, r_key.seqno );
787      pp= append_main_item(firstpp, pp, &r_key);
788
789      if ( (readpp->pos != killblk ) && (0!=readpp->pos) )
790      {  /* pos can get to 0 at end of main seq, if still diffs left...*/
791         if (readpp->is->method->debug >3)  
792             logf(LOG_LOG,"isamd_merge: released block %d (%d:%d) now %d=%d:%d",
793                 isamd_addr(killblk,readpp->cat), readpp->cat, killblk,
794                 isamd_addr(readpp->pos,readpp->cat),readpp->cat, readpp->pos );
795         isamd_release_block(readpp->is, readpp->cat, readpp->pos);
796         killblk=readpp->pos;
797      }
798
799      /* (try to) read next item */
800      r_ptr= (char *) &r_key;
801      r_more = isamd_read_item_merge( readpp, &r_ptr,0,filt);
802
803   } /* while read */
804   
805   
806   isamd_reduceblock(pp);  /* reduce size if possible */
807   if (0==firstpp->next)
808     firstpp->next = isamd_addr(pp->pos,pp->cat);
809   save_last_pp(pp);
810   if (readpp->is->method->debug >4) 
811       logf(LOG_LOG,"isamd_merge: saved last block %d=%d:%d",
812             isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos);
813   isamd_pp_close(pp);
814
815   if (readpp->is->method->debug >5) 
816         logf(LOG_LOG,"isamd_merge: closing readpp %d=%d:%d di=%p",
817               isamd_addr(readpp->pos,readpp->cat), readpp->cat, readpp->pos,
818               readpp->diffinfo);
819   isamd_pp_close(readpp); /* pos is 0 by now, at eof. close works anyway */
820
821   if (readpp->is->method->debug >2)  
822       logf(LOG_LOG,"isamd_merge: merge ret f=%d=%d:%d pp=%d=%d:%d",
823             isamd_addr(firstpp->pos,pp->cat), firstpp->cat, firstpp->pos,
824             isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos);
825
826   firstpp->size = firstpp->offset = ISAMD_BLOCK_OFFSET_1;  /* nothing there */
827   memset(firstpp->buf,'\0',firstpp->is->method->filecat[firstpp->cat].bsize);
828   save_first_pp(firstpp);
829   retpos = isamd_addr(firstpp->pos, firstpp->cat);
830   isamd_pp_close(firstpp);
831
832   /* Create the dict entry */
833   /*!*/ /* it could be this could go in the dict as well, if there's */
834         /* been really many deletes. Somehow I suspect that is not the */
835         /* case. FIXME: Collect statistics and see if needed */
836   dictentry[0]=0; /* mark as a real isam */
837   memcpy(dictentry+1, &retpos, sizeof(ISAMD_P));
838   dictlen=sizeof(ISAMD_P)+1;
839   return dictlen;
840   
841 } /* merge */
842
843
844
845
846 /***************************************************************
847  * Appending diffs 
848  ***************************************************************/
849
850
851
852 static int append_diffs(
853       ISAMD is, 
854       char *dictentry, int dictlen,
855       FILTER filt)
856 {
857    ISAMD_P ipos;
858    struct it_key i_key;    /* one input item */
859    char *i_item = (char *) &i_key;  /* same as chars */
860    char *i_ptr=i_item;
861    int i_more =1;
862    int i_mode;     /* 0 for delete, 1 for insert */ 
863
864    ISAMD_PP firstpp;
865    char hexbuff[64];
866    int diffidx=0;
867    int maxsize=0;
868    int difflenidx;
869    char codebuff[128];
870    char *c_ptr = codebuff;
871    int codelen;
872    int merge_rc;
873    ISAMD_P retpos;
874    int dsize;
875
876    if (0==dictlen)
877    {
878        firstpp=isamd_pp_create(is, 0 );
879        firstpp->size=firstpp->offset=ISAMD_BLOCK_OFFSET_1;
880          /* create in smallest category, will expand later */
881        ++(is->no_fbuilds);
882    } 
883    else
884    {
885        firstpp=isamd_pp_open(is, dictentry, dictlen);
886        if (dictentry[0] )
887           ipos=0;
888        else 
889            memcpy(&ipos,dictentry+1,sizeof(ISAMD_P));
890        ++(is->no_appds);
891    }
892
893    if (is->method->debug >2) 
894       logf(LOG_LOG,"isamd_appd: Start ipos=%d=%d:%d n=%d=%d:%d nk=%d sz=%d",
895         ipos, isamd_type(ipos), isamd_block(ipos),
896         firstpp->next, isamd_type(firstpp->next), isamd_block(firstpp->next),
897         firstpp->numKeys, firstpp->size);
898    maxsize = is->method->filecat[firstpp->cat].bsize; 
899    
900    difflenidx = diffidx = firstpp->size;
901    
902    diffidx+=sizeof(int);  /* difflen will be stored here */
903    
904    /* read first input */
905    i_more = filter_read(filt, &i_key, &i_mode); 
906    /* i_more = (*data->read_item)(data->clientData, &i_ptr, &i_mode); */
907
908    if (is->method->debug >6)
909       logf(LOG_LOG,"isamd_appd: start m=%d %d.%d=%x.%x: %d",
910          i_mode, 
911          i_key.sysno, i_key.seqno, 
912          i_key.sysno, i_key.seqno,
913          i_key.sysno*2+i_mode);
914
915    while (i_more)
916    {     
917       /* store the mode bit inside key */
918       assert( ((i_key.seqno<<1)>>1) == i_key.seqno); /* can spare the bit */
919       i_key.seqno = i_key.seqno * 2 + i_mode;  
920
921       c_ptr=codebuff;
922       i_ptr=i_item; 
923       (*is->method->code_item)(ISAMD_ENCODE, firstpp->decodeClientData, 
924                                &c_ptr, &i_ptr);
925       codelen = c_ptr - codebuff;
926       assert ( (codelen<128) && (codelen>0));
927       if (is->method->debug >7)
928          logf(LOG_LOG,"isamd_appd: coded %d: %s (nk=%d) (ix=%d)",
929              codelen, hexdump(codebuff, codelen,hexbuff), 
930              firstpp->numKeys,diffidx);
931
932       if (diffidx + codelen > maxsize )
933       { /* block full */
934          while ( (firstpp->cat < firstpp->is->max_cat) &&
935                  (diffidx + codelen > maxsize) )
936          { /* try to increase the block size */
937              if (firstpp->pos > 0)  /* free the old block if allocated */
938                  isamd_release_block(is, firstpp->cat, firstpp->pos);
939              ++firstpp->cat;
940              maxsize = is->method->filecat[firstpp->cat].bsize; 
941              firstpp->pos=0; /* need to allocate it when saving */             
942              if (is->method->debug >3)
943                 logf(LOG_LOG,"isamd_appd: increased diff block sz to %d (%d)",
944                    firstpp->cat, maxsize);
945          }
946          if  ((firstpp->cat >= firstpp->is->max_cat) &&
947                  (diffidx + codelen > maxsize) )
948          { /* max size - can't help, need to merge it */
949              if (is->method->debug >7)
950                 logf(LOG_LOG,"isamd_appd: need to merge");
951              if (is->method->debug >9)  /* !!!!! */
952                 logf(LOG_LOG,"isamd_appd: going to merge with m=%d %d.%d",
953                      i_mode, i_key.sysno, i_key.seqno);
954              merge_rc = merge (firstpp, &i_key, filt, dictentry, dictlen);
955              if (0!=merge_rc)
956                return merge_rc;  /* merge handled them all ! */
957              assert(!"merge returned zero ??");
958          } /* need to merge */
959       } /* block full */
960
961       if (!( diffidx+codelen <= maxsize )) 
962       { /* bug hunting */
963          logf(LOG_LOG,"OOPS, diffidx problem: d=%d c=%d s=%d > m=%d",
964            diffidx, codelen, diffidx+codelen, maxsize);
965          logf(LOG_LOG,"ipos=%d f=%d=%d:%d",
966            ipos, 
967            isamd_addr(firstpp->pos, firstpp->cat),
968            firstpp->cat, firstpp->pos );
969       }
970       assert ( diffidx+codelen <= maxsize );
971       
972       /* save the diff */ 
973       memcpy(&(firstpp->buf[diffidx]),codebuff,codelen);
974       diffidx += codelen;
975       firstpp->size = firstpp->offset = diffidx;
976       
977       if (i_mode)
978         firstpp->numKeys++; /* insert diff */
979       else
980         firstpp->numKeys--; /* delete diff */ 
981
982       /* update length of this diff run */
983       memcpy(&(firstpp->buf[difflenidx]),&diffidx,sizeof(diffidx));
984       
985       /* (try to) read the next input */
986       i_ptr = i_item;
987       i_more = filter_read(filt, &i_key, &i_mode); 
988     /*  i_more = (*data->read_item)(data->clientData, &i_ptr, &i_mode); */
989       if ( (i_more) && (is->method->debug >6) )
990          logf(LOG_LOG,"isamd_appd: got m=%d %d.%d=%x.%x: %d",
991             i_mode, 
992             i_key.sysno, i_key.seqno, 
993             i_key.sysno, i_key.seqno,
994             i_key.sysno*2+i_mode);
995    } /* more loop */
996
997    /* clear the next difflen, if room for such */
998    difflenidx = diffidx;
999    while ( (difflenidx-diffidx<=sizeof(int)+1) && (difflenidx<maxsize))
1000      firstpp->buf[difflenidx++]='\0';
1001
1002    if (firstpp->numKeys==0)
1003    { 
1004        /* FIXME: Release blocks that may be allocated !!! */
1005        return 0; /* don't bother storing this! */
1006    }
1007
1008    dsize=diffidx-ISAMD_BLOCK_OFFSET_1;
1009    /* logf(LOG_LOG,"!! nxt=%d diffidx=%d ds=%d", 
1010            firstpp->next, diffidx, dsize);  */
1011
1012    if ( (0==firstpp->next) && (dsize <ISAMD_MAX_DICT_LEN))
1013    {
1014         /* logf(LOG_LOG,"building a dict entry!!"); */
1015         assert(firstpp->numKeys < 128);
1016         assert(firstpp->numKeys >0);
1017         /* actually, 255 is good enough, but sign mismatches... */
1018         /* in real life, 4-5 is as much as we can hope for, as long */
1019         /* as ISAMD_MAX_DICT_LEN is reasonably small (8) */
1020         dictentry[0]=firstpp->numKeys;
1021         memcpy(dictentry+1, firstpp->buf+ISAMD_BLOCK_OFFSET_1, dsize);
1022         dictlen=dsize+1;
1023    }
1024    else 
1025    {
1026        if (0==firstpp->pos)  /* need to (re)alloc the block */
1027            firstpp->pos = isamd_alloc_block(is, firstpp->cat);
1028        retpos = save_first_pp( firstpp );
1029        isamd_pp_close(firstpp);
1030        dictentry[0]=0; /* mark as a real isam */
1031        memcpy(dictentry+1, &retpos, sizeof(ISAMD_P));
1032        dictlen=sizeof(ISAMD_P)+1;
1033    }
1034     
1035    return dictlen;
1036 } /* append_diffs */
1037
1038
1039
1040
1041 /*************************************************************
1042  * isamd_append itself
1043  *************************************************************/
1044
1045 int isamd_append (ISAMD is, char *dictentry, int dictlen, ISAMD_I data)
1046 /*ISAMD_P isamd_append (ISAMD is, ISAMD_P ipos, ISAMD_I data) */
1047 {
1048    FILTER F = filter_open(is,data);
1049    int newlen=0;
1050
1051    if ( filter_isempty(F) ) /* can be, if del-ins of the same */
1052    {
1053       if (is->method->debug >3) 
1054          logf(LOG_LOG,"isamd_appd: nothing to do ");
1055       filter_close(F);
1056       ++(is->no_non);
1057       return dictlen; /* without doing anything at all */
1058    }
1059
1060 #ifdef SKIPTHIS 
1061    /* The old way to handle singletons */
1062    if ( ( 0==ipos) && filter_only_one(F) )
1063    {
1064       struct it_key k;
1065       int mode;
1066       filter_read(F,&k,&mode);     
1067       assert(mode); 
1068       rc = singleton_encode(&k);
1069       if (!rc) 
1070       {
1071       if (is->method->debug >9) 
1072          logf(LOG_LOG,"isamd_appd: singleton didn't fit, backfilling");
1073          filter_backfill(F,&k, mode);
1074       }
1075       if (is->method->debug >9) 
1076          logf(LOG_LOG,"isamd_appd: singleton %d (%x)",
1077            rc,rc);
1078       if (rc)
1079         is->no_singles++;
1080       assert ( (rc==0) || is_singleton(rc) );
1081    }
1082    newlen = append_diffs(is,ipos,F); 
1083 #endif
1084    newlen = append_diffs(is,dictentry,dictlen,F); 
1085    filter_close(F);
1086
1087    if (is->method->debug >2) 
1088       logf(LOG_LOG,"isamd_appd: ret len=%d ", newlen);
1089    return newlen;
1090 } /*  isamd_append */
1091
1092
1093
1094
1095
1096
1097
1098 /*
1099  * $Log: merge-d.c,v $
1100  * Revision 1.29  2002-11-26 22:18:34  adam
1101  * Remove // comments
1102  *
1103  * Revision 1.28  2002/08/02 19:26:56  adam
1104  * Towards GPL
1105  *
1106  * Revision 1.27  2002/07/12 18:12:21  heikki
1107  * Isam-D now stores small entries directly in the dictionary.
1108  * Needs more tuning and cleaning...
1109  *
1110  * Revision 1.26  2002/07/11 16:16:00  heikki
1111  * Fixed a bug in isamd, failed to store a single key when its bits
1112  * did not fit into a singleton.
1113  *
1114  * Revision 1.25  1999/11/30 13:48:04  adam
1115  * Improved installation. Updated for inclusion of YAZ header files.
1116  *
1117  * Revision 1.24  1999/10/05 09:57:40  heikki
1118  * Tuning the isam-d (and fixed a small "detail")
1119  *
1120  * Revision 1.23  1999/09/27 14:36:36  heikki
1121  * singletons
1122  *
1123  * Revision 1.22  1999/09/23 18:01:18  heikki
1124  * singleton optimising
1125  *
1126  * Revision 1.21  1999/09/21 17:36:43  heikki
1127  * Added filter function. Not much of effect on the small test set...
1128  *
1129  * Revision 1.20  1999/09/20 15:48:06  heikki
1130  * Small changes
1131  *
1132  * Revision 1.19  1999/09/13 13:28:28  heikki
1133  * isam-d optimizing: merging input data in the same go
1134  *
1135  * Revision 1.18  1999/08/25 18:09:24  heikki
1136  * Starting to optimize
1137  *
1138  * Revision 1.17  1999/08/24 13:17:42  heikki
1139  * Block sizes, comments
1140  *
1141  * Revision 1.16  1999/08/24 10:12:02  heikki
1142  * Comments about optimising
1143  *
1144  * Revision 1.15  1999/08/22 08:26:34  heikki
1145  * COmments
1146  *
1147  * Revision 1.14  1999/08/20 12:25:58  heikki
1148  * Statistics in isamd
1149  *
1150  * Revision 1.13  1999/08/18 13:59:19  heikki
1151  * Fixed another unlikely difflen bug
1152  *
1153  * Revision 1.12  1999/08/18 13:28:17  heikki
1154  * Set log levels to decent values
1155  *
1156  * Revision 1.11  1999/08/18 10:37:11  heikki
1157  * Fixed (another) difflen bug
1158  *
1159  * Revision 1.10  1999/08/18 09:13:31  heikki
1160  * Fixed a detail
1161  *
1162  * Revision 1.9  1999/08/17 19:46:53  heikki
1163  * Fixed a memory leak
1164  *
1165  * Revision 1.8  1999/08/07 11:30:59  heikki
1166  * Bug fixing (still a mem leak somewhere)
1167  *
1168  * Revision 1.7  1999/08/04 14:21:18  heikki
1169  * isam-d seems to be working.
1170  *
1171  * Revision 1.6  1999/07/23 15:43:05  heikki
1172  * Hunted a few bugs in isam-d. Still crashes on the long test run
1173  *
1174  * Revision 1.5  1999/07/23 13:58:52  heikki
1175  * merged closer to working, still fails on filling a separate, large block
1176  *
1177  * Revision 1.4  1999/07/21 14:53:55  heikki
1178  * isamd read and write functions work, except when block full
1179  * Merge missing still. Need to split some functions
1180  *
1181  * Revision 1.1  1999/07/14 13:14:47  heikki
1182  * Created empty
1183  *
1184  *
1185  */
1186
1187