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