Towards GPL
[idzebra-moved-to-github.git] / isamc / merge-d.c
1 /* $Id: merge-d.c,v 1.28 2002-08-02 19:26:56 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   //readpp->diffbuf=readpp->buf;  // diffinfo has to duplicate it!
741   //getDiffInfo(readpp);  // first read will make the diffinfo, at init
742   
743   if (readpp->is->method->debug >4) 
744       logf(LOG_LOG,"isamd_merge: f=%d=%d:%d n=%d=%d:%d",
745         isamd_addr(firstpp->pos,firstpp->cat), firstpp->cat, firstpp->pos,
746         firstpp->next, isamd_type(firstpp->next), isamd_block(firstpp->next));  
747
748   /* release our data block. Do before reading, when pos is stable ! */
749   killblk=firstpp->pos;
750   if (killblk)
751   {
752       isamd_release_block(firstpp->is, firstpp->cat, killblk);
753       if (readpp->is->method->debug >3)   
754           logf(LOG_LOG,"isamd_merge: released old firstblock %d (%d:%d)",
755               isamd_addr(killblk,firstpp->cat), firstpp->cat, killblk );
756   }
757   
758
759   r_ptr= (char *) &r_key;
760   r_more = isamd_read_item_merge( readpp, &r_ptr, p_key, filt);
761   if (!r_more)  
762   { /* oops, all data has been deleted! what to do??? */
763     /* never mind, we have at least one more delta to add to the block */
764     /* pray that is not a delete as well... */
765     r_key.sysno = 0;
766     r_key.seqno = 0;
767      if (readpp->is->method->debug >5) 
768          logf(LOG_LOG,"isamd_merge:all data has been deleted (nk=%d) ",
769             readpp->numKeys);
770   }
771
772
773   /* set up the new blocks for simple writing */
774   /* firstpp=isamd_pp_open(readpp->is,isamd_addr(0, diffcat)); */
775   firstpp=isamd_pp_create(readpp->is, diffcat);
776   firstpp->pos=isamd_alloc_block(firstpp->is,diffcat);
777   if (readpp->is->method->debug >3)   
778       logf(LOG_LOG,"isamd_merge: allocated new firstpp %d=%d:%d",
779           isamd_addr(firstpp->pos,firstpp->cat), firstpp->cat, firstpp->pos );
780   
781   pp=isamd_pp_create(readpp->is,readpp->is->max_cat );
782   pp->offset=pp->size=ISAMD_BLOCK_OFFSET_N;
783   
784   while (r_more)
785   {
786      if (readpp->is->method->debug >6) 
787          logf(LOG_LOG,"isamd_merge: got key %d.%d",
788            r_key.sysno, r_key.seqno );
789      pp= append_main_item(firstpp, pp, &r_key);
790
791      if ( (readpp->pos != killblk ) && (0!=readpp->pos) )
792      {  /* pos can get to 0 at end of main seq, if still diffs left...*/
793         if (readpp->is->method->debug >3)  
794             logf(LOG_LOG,"isamd_merge: released block %d (%d:%d) now %d=%d:%d",
795                 isamd_addr(killblk,readpp->cat), readpp->cat, killblk,
796                 isamd_addr(readpp->pos,readpp->cat),readpp->cat, readpp->pos );
797         isamd_release_block(readpp->is, readpp->cat, readpp->pos);
798         killblk=readpp->pos;
799      }
800
801      /* (try to) read next item */
802      r_ptr= (char *) &r_key;
803      r_more = isamd_read_item_merge( readpp, &r_ptr,0,filt);
804
805   } /* while read */
806   
807   
808 //  firstpp->diffs=0; 
809
810
811   isamd_reduceblock(pp);  /* reduce size if possible */
812   if (0==firstpp->next)
813     firstpp->next = isamd_addr(pp->pos,pp->cat);
814   save_last_pp(pp);
815   if (readpp->is->method->debug >4) 
816       logf(LOG_LOG,"isamd_merge: saved last block %d=%d:%d",
817             isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos);
818   isamd_pp_close(pp);
819
820   if (readpp->is->method->debug >5) 
821         logf(LOG_LOG,"isamd_merge: closing readpp %d=%d:%d di=%p",
822               isamd_addr(readpp->pos,readpp->cat), readpp->cat, readpp->pos,
823               readpp->diffinfo);
824   isamd_pp_close(readpp); /* pos is 0 by now, at eof. close works anyway */
825
826   if (readpp->is->method->debug >2)  
827       logf(LOG_LOG,"isamd_merge: merge ret f=%d=%d:%d pp=%d=%d:%d",
828             isamd_addr(firstpp->pos,pp->cat), firstpp->cat, firstpp->pos,
829             isamd_addr(pp->pos,pp->cat), pp->cat, pp->pos);
830
831   firstpp->size = firstpp->offset = ISAMD_BLOCK_OFFSET_1;  /* nothing there */
832   memset(firstpp->buf,'\0',firstpp->is->method->filecat[firstpp->cat].bsize);
833   save_first_pp(firstpp);
834   retpos = isamd_addr(firstpp->pos, firstpp->cat);
835   isamd_pp_close(firstpp);
836
837   /* Create the dict entry */
838   /*!*/ /* it could be this could go in the dict as well, if there's */
839         /* been really many deletes. Somehow I suspect that is not the */
840         /* case. FIXME: Collect statistics and see if needed */
841   dictentry[0]=0; /* mark as a real isam */
842   memcpy(dictentry+1, &retpos, sizeof(ISAMD_P));
843   dictlen=sizeof(ISAMD_P)+1;
844   return dictlen;
845   
846 } /* merge */
847
848
849
850
851 /***************************************************************
852  * Appending diffs 
853  ***************************************************************/
854
855
856
857 static int append_diffs(
858       ISAMD is, 
859       char *dictentry, int dictlen,
860       FILTER filt)
861 {
862    ISAMD_P ipos;
863    struct it_key i_key;    /* one input item */
864    char *i_item = (char *) &i_key;  /* same as chars */
865    char *i_ptr=i_item;
866    int i_more =1;
867    int i_mode;     /* 0 for delete, 1 for insert */ 
868
869    ISAMD_PP firstpp;
870    char hexbuff[64];
871    int diffidx=0;
872    int maxsize=0;
873    int difflenidx;
874    char codebuff[128];
875    char *c_ptr = codebuff;
876    int codelen;
877    int merge_rc;
878    ISAMD_P retpos;
879    int dsize;
880
881    if (0==dictlen)
882    {
883        firstpp=isamd_pp_create(is, 0 );
884        firstpp->size=firstpp->offset=ISAMD_BLOCK_OFFSET_1;
885          /* create in smallest category, will expand later */
886        ++(is->no_fbuilds);
887    } 
888    else
889    {
890        firstpp=isamd_pp_open(is, dictentry, dictlen);
891        if (dictentry[0] )
892           ipos=0;
893        else 
894            memcpy(&ipos,dictentry+1,sizeof(ISAMD_P));
895        ++(is->no_appds);
896    }
897
898    if (is->method->debug >2) 
899       logf(LOG_LOG,"isamd_appd: Start ipos=%d=%d:%d n=%d=%d:%d nk=%d sz=%d",
900         ipos, isamd_type(ipos), isamd_block(ipos),
901         firstpp->next, isamd_type(firstpp->next), isamd_block(firstpp->next),
902         firstpp->numKeys, firstpp->size);
903    maxsize = is->method->filecat[firstpp->cat].bsize; 
904    
905    difflenidx = diffidx = firstpp->size;
906    
907    diffidx+=sizeof(int);  /* difflen will be stored here */
908    
909    /* read first input */
910    //i_ptr = i_item;   //!!!
911    i_more = filter_read(filt, &i_key, &i_mode); 
912    /* i_more = (*data->read_item)(data->clientData, &i_ptr, &i_mode); */
913
914    if (is->method->debug >6)
915       logf(LOG_LOG,"isamd_appd: start m=%d %d.%d=%x.%x: %d",
916          i_mode, 
917          i_key.sysno, i_key.seqno, 
918          i_key.sysno, i_key.seqno,
919          i_key.sysno*2+i_mode);
920
921    while (i_more)
922    {     
923       /* store the mode bit inside key */
924       assert( ((i_key.seqno<<1)>>1) == i_key.seqno); /* can spare the bit */
925       i_key.seqno = i_key.seqno * 2 + i_mode;  
926
927       c_ptr=codebuff;
928       i_ptr=i_item; 
929       (*is->method->code_item)(ISAMD_ENCODE, firstpp->decodeClientData, 
930                                &c_ptr, &i_ptr);
931       codelen = c_ptr - codebuff;
932       assert ( (codelen<128) && (codelen>0));
933       if (is->method->debug >7)
934          logf(LOG_LOG,"isamd_appd: coded %d: %s (nk=%d) (ix=%d)",
935              codelen, hexdump(codebuff, codelen,hexbuff), 
936              firstpp->numKeys,diffidx);
937
938       if (diffidx + codelen > maxsize )
939       { /* block full */
940          while ( (firstpp->cat < firstpp->is->max_cat) &&
941                  (diffidx + codelen > maxsize) )
942          { /* try to increase the block size */
943              if (firstpp->pos > 0)  /* free the old block if allocated */
944                  isamd_release_block(is, firstpp->cat, firstpp->pos);
945              ++firstpp->cat;
946              maxsize = is->method->filecat[firstpp->cat].bsize; 
947              firstpp->pos=0; /* need to allocate it when saving */             
948              if (is->method->debug >3)
949                 logf(LOG_LOG,"isamd_appd: increased diff block sz to %d (%d)",
950                    firstpp->cat, maxsize);
951          }
952          if  ((firstpp->cat >= firstpp->is->max_cat) &&
953                  (diffidx + codelen > maxsize) )
954          { /* max size - can't help, need to merge it */
955              if (is->method->debug >7)
956                 logf(LOG_LOG,"isamd_appd: need to merge");
957              if (is->method->debug >9)  //!!!!!
958                 logf(LOG_LOG,"isamd_appd: going to merge with m=%d %d.%d",
959                      i_mode, i_key.sysno, i_key.seqno);
960              merge_rc = merge (firstpp, &i_key, filt, dictentry, dictlen);
961              if (0!=merge_rc)
962                return merge_rc;  /* merge handled them all ! */
963              assert(!"merge returned zero ??");
964          } /* need to merge */
965       } /* block full */
966
967       if (!( diffidx+codelen <= maxsize )) 
968       { /* bug hunting */
969          logf(LOG_LOG,"OOPS, diffidx problem: d=%d c=%d s=%d > m=%d",
970            diffidx, codelen, diffidx+codelen, maxsize);
971          logf(LOG_LOG,"ipos=%d f=%d=%d:%d",
972            ipos, 
973            isamd_addr(firstpp->pos, firstpp->cat),
974            firstpp->cat, firstpp->pos );
975       }
976       assert ( diffidx+codelen <= maxsize );
977       
978       /* save the diff */ 
979       memcpy(&(firstpp->buf[diffidx]),codebuff,codelen);
980       diffidx += codelen;
981       firstpp->size = firstpp->offset = diffidx;
982       
983       if (i_mode)
984         firstpp->numKeys++; /* insert diff */
985       else
986         firstpp->numKeys--; /* delete diff */ 
987
988       /* update length of this diff run */
989       memcpy(&(firstpp->buf[difflenidx]),&diffidx,sizeof(diffidx));
990       
991       /* (try to) read the next input */
992       i_ptr = i_item;
993       i_more = filter_read(filt, &i_key, &i_mode); 
994     /*  i_more = (*data->read_item)(data->clientData, &i_ptr, &i_mode); */
995       if ( (i_more) && (is->method->debug >6) )
996          logf(LOG_LOG,"isamd_appd: got m=%d %d.%d=%x.%x: %d",
997             i_mode, 
998             i_key.sysno, i_key.seqno, 
999             i_key.sysno, i_key.seqno,
1000             i_key.sysno*2+i_mode);
1001    } /* more loop */
1002
1003    /* clear the next difflen, if room for such */
1004    difflenidx = diffidx;
1005    while ( (difflenidx-diffidx<=sizeof(int)+1) && (difflenidx<maxsize))
1006      firstpp->buf[difflenidx++]='\0';
1007
1008    if (firstpp->numKeys==0)
1009    { 
1010        /* FIXME: Release blocks that may be allocated !!! */
1011        return 0; /* don't bother storing this! */
1012    }
1013
1014    dsize=diffidx-ISAMD_BLOCK_OFFSET_1;
1015    /* logf(LOG_LOG,"!! nxt=%d diffidx=%d ds=%d", 
1016            firstpp->next, diffidx, dsize);  */
1017
1018    if ( (0==firstpp->next) && (dsize <ISAMD_MAX_DICT_LEN))
1019    {
1020         /* logf(LOG_LOG,"building a dict entry!!"); */
1021         assert(firstpp->numKeys < 128);
1022         assert(firstpp->numKeys >0);
1023         /* actually, 255 is good enough, but sign mismatches... */
1024         /* in real life, 4-5 is as much as we can hope for, as long */
1025         /* as ISAMD_MAX_DICT_LEN is reasonably small (8) */
1026         dictentry[0]=firstpp->numKeys;
1027         memcpy(dictentry+1, firstpp->buf+ISAMD_BLOCK_OFFSET_1, dsize);
1028         dictlen=dsize+1;
1029    }
1030    else 
1031    {
1032        if (0==firstpp->pos)  /* need to (re)alloc the block */
1033            firstpp->pos = isamd_alloc_block(is, firstpp->cat);
1034        retpos = save_first_pp( firstpp );
1035        isamd_pp_close(firstpp);
1036        dictentry[0]=0; /* mark as a real isam */
1037        memcpy(dictentry+1, &retpos, sizeof(ISAMD_P));
1038        dictlen=sizeof(ISAMD_P)+1;
1039    }
1040     
1041    return dictlen;
1042 } /* append_diffs */
1043
1044
1045
1046
1047 /*************************************************************
1048  * isamd_append itself
1049  *************************************************************/
1050
1051 int isamd_append (ISAMD is, char *dictentry, int dictlen, ISAMD_I data)
1052 /*ISAMD_P isamd_append (ISAMD is, ISAMD_P ipos, ISAMD_I data) */
1053 {
1054    FILTER F = filter_open(is,data);
1055    int newlen=0;
1056
1057    if ( filter_isempty(F) ) /* can be, if del-ins of the same */
1058    {
1059       if (is->method->debug >3) 
1060          logf(LOG_LOG,"isamd_appd: nothing to do ");
1061       filter_close(F);
1062       ++(is->no_non);
1063       return dictlen; /* without doing anything at all */
1064    }
1065
1066 #ifdef SKIPTHIS 
1067    /* The old way to handle singletons */
1068    if ( ( 0==ipos) && filter_only_one(F) )
1069    {
1070       struct it_key k;
1071       int mode;
1072       filter_read(F,&k,&mode);     
1073       assert(mode); 
1074       rc = singleton_encode(&k);
1075       if (!rc) 
1076       {
1077       if (is->method->debug >9) 
1078          logf(LOG_LOG,"isamd_appd: singleton didn't fit, backfilling");
1079          filter_backfill(F,&k, mode);
1080       }
1081       if (is->method->debug >9) 
1082          logf(LOG_LOG,"isamd_appd: singleton %d (%x)",
1083            rc,rc);
1084       if (rc)
1085         is->no_singles++;
1086       assert ( (rc==0) || is_singleton(rc) );
1087    }
1088    newlen = append_diffs(is,ipos,F); 
1089 #endif
1090    newlen = append_diffs(is,dictentry,dictlen,F); 
1091    filter_close(F);
1092
1093    if (is->method->debug >2) 
1094       logf(LOG_LOG,"isamd_appd: ret len=%d ", newlen);
1095    return newlen;
1096 } /*  isamd_append */
1097
1098
1099
1100
1101
1102
1103
1104 /*
1105  * $Log: merge-d.c,v $
1106  * Revision 1.28  2002-08-02 19:26:56  adam
1107  * Towards GPL
1108  *
1109  * Revision 1.27  2002/07/12 18:12:21  heikki
1110  * Isam-D now stores small entries directly in the dictionary.
1111  * Needs more tuning and cleaning...
1112  *
1113  * Revision 1.26  2002/07/11 16:16:00  heikki
1114  * Fixed a bug in isamd, failed to store a single key when its bits
1115  * did not fit into a singleton.
1116  *
1117  * Revision 1.25  1999/11/30 13:48:04  adam
1118  * Improved installation. Updated for inclusion of YAZ header files.
1119  *
1120  * Revision 1.24  1999/10/05 09:57:40  heikki
1121  * Tuning the isam-d (and fixed a small "detail")
1122  *
1123  * Revision 1.23  1999/09/27 14:36:36  heikki
1124  * singletons
1125  *
1126  * Revision 1.22  1999/09/23 18:01:18  heikki
1127  * singleton optimising
1128  *
1129  * Revision 1.21  1999/09/21 17:36:43  heikki
1130  * Added filter function. Not much of effect on the small test set...
1131  *
1132  * Revision 1.20  1999/09/20 15:48:06  heikki
1133  * Small changes
1134  *
1135  * Revision 1.19  1999/09/13 13:28:28  heikki
1136  * isam-d optimizing: merging input data in the same go
1137  *
1138  * Revision 1.18  1999/08/25 18:09:24  heikki
1139  * Starting to optimize
1140  *
1141  * Revision 1.17  1999/08/24 13:17:42  heikki
1142  * Block sizes, comments
1143  *
1144  * Revision 1.16  1999/08/24 10:12:02  heikki
1145  * Comments about optimising
1146  *
1147  * Revision 1.15  1999/08/22 08:26:34  heikki
1148  * COmments
1149  *
1150  * Revision 1.14  1999/08/20 12:25:58  heikki
1151  * Statistics in isamd
1152  *
1153  * Revision 1.13  1999/08/18 13:59:19  heikki
1154  * Fixed another unlikely difflen bug
1155  *
1156  * Revision 1.12  1999/08/18 13:28:17  heikki
1157  * Set log levels to decent values
1158  *
1159  * Revision 1.11  1999/08/18 10:37:11  heikki
1160  * Fixed (another) difflen bug
1161  *
1162  * Revision 1.10  1999/08/18 09:13:31  heikki
1163  * Fixed a detail
1164  *
1165  * Revision 1.9  1999/08/17 19:46:53  heikki
1166  * Fixed a memory leak
1167  *
1168  * Revision 1.8  1999/08/07 11:30:59  heikki
1169  * Bug fixing (still a mem leak somewhere)
1170  *
1171  * Revision 1.7  1999/08/04 14:21:18  heikki
1172  * isam-d seems to be working.
1173  *
1174  * Revision 1.6  1999/07/23 15:43:05  heikki
1175  * Hunted a few bugs in isam-d. Still crashes on the long test run
1176  *
1177  * Revision 1.5  1999/07/23 13:58:52  heikki
1178  * merged closer to working, still fails on filling a separate, large block
1179  *
1180  * Revision 1.4  1999/07/21 14:53:55  heikki
1181  * isamd read and write functions work, except when block full
1182  * Merge missing still. Need to split some functions
1183  *
1184  * Revision 1.1  1999/07/14 13:14:47  heikki
1185  * Created empty
1186  *
1187  *
1188  */
1189
1190