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