af83ebd132cdb6512c375cc040c7ef9103993ef8
[idzebra-moved-to-github.git] / isamc / isamd.c
1 /*
2  * Copyright (c) 1995-1998, Index Data.
3  * See the file LICENSE for details.
4  * $Id: isamd.c,v 1.11 1999-08-25 18:09:24 heikki Exp $ 
5  *
6  * Isamd - isam with diffs 
7  * Programmed by: Heikki Levanto
8  *
9  * Todo
10  *  - Statistics are missing and/or completely wrong
11  *  - Lots of code stolen from isamc, not all needed any more
12  */
13
14
15 #include <stdlib.h>
16 #include <assert.h>
17 #include <string.h>
18 #include <stdio.h>
19
20 #include <log.h>
21 #include "../index/index.h"  /* isamd uses the internal structure of it_key */
22 #include "isamd-p.h"
23
24 static void flush_block (ISAMD is, int cat);
25 static void release_fc (ISAMD is, int cat);
26 static void init_fc (ISAMD is, int cat);
27
28 #define ISAMD_FREELIST_CHUNK 1
29
30 #define SMALL_TEST 1
31
32 ISAMD_M isamd_getmethod (ISAMD_M me)
33 {
34     static struct ISAMD_filecat_s def_cat[] = {
35 #if SMALL_TEST
36 /*        blocksz,   max. Unused time being */
37         {    20,   40 },
38         {    32,    0 },
39 #else
40         {    32,    1 },
41         {   128,    1 },
42         {   512,    1 },
43         {  2048,    1 },
44         {  8192,    1 },
45         { 32768,    1 },
46         {131072,    0 },
47 #endif 
48
49 /* old values from isamc, long time ago...
50         {    24,   40 },
51         {   128,  256 },
52         {   512, 1024 },
53         {  2048, 4096 },
54         {  8192,16384 },
55         { 32768,   0  },
56 */
57
58     };
59     ISAMD_M m = (ISAMD_M) xmalloc (sizeof(*m));  /* never released! */
60     m->filecat = def_cat;                        /* ok, only alloc'd once */
61
62     m->code_start = NULL;
63     m->code_item = NULL;
64     m->code_stop = NULL;
65     m->code_reset = NULL;
66
67     m->compare_item = NULL;
68
69     m->debug = 0; /* default to no debug */
70
71     m->max_blocks_mem = 10;
72
73     return m;
74 }
75
76
77
78 ISAMD isamd_open (BFiles bfs, const char *name, int writeflag, ISAMD_M method)
79 {
80     ISAMD is;
81     ISAMD_filecat filecat;
82     int i = 0;
83
84     is = (ISAMD) xmalloc (sizeof(*is));
85
86     is->method = (ISAMD_M) xmalloc (sizeof(*is->method));
87     memcpy (is->method, method, sizeof(*method));
88     filecat = is->method->filecat;
89     assert (filecat);
90
91     /* determine number of block categories */
92     if (is->method->debug>0)
93         logf (LOG_LOG, "isamd: bsize  maxkeys");
94     do
95     {
96         if (is->method->debug>0)
97             logf (LOG_LOG, "isamd:%6d %6d",
98                   filecat[i].bsize, filecat[i].mblocks);
99     } while (filecat[i++].mblocks);
100     is->no_files = i;
101     is->max_cat = --i;
102  
103     assert (is->no_files > 0);
104     assert (is->max_cat <=8 ); /* we have only 3 bits for it */
105     
106     is->files = (ISAMD_file) xmalloc (sizeof(*is->files)*is->no_files);
107
108     for (i = 0; i<is->no_files; i++)
109     {
110         char fname[512];
111
112         sprintf (fname, "%s%c", name, i+'A');
113         is->files[i].bf = bf_open (bfs, fname, is->method->filecat[i].bsize,
114                                    writeflag);
115         is->files[i].head_is_dirty = 0;
116         if (!bf_read (is->files[i].bf, 0, 0, sizeof(ISAMD_head),
117                      &is->files[i].head))
118         {
119             is->files[i].head.lastblock = 1;
120             is->files[i].head.freelist = 0;
121         }
122         is->files[i].alloc_entries_num = 0;
123         is->files[i].alloc_entries_max =
124             is->method->filecat[i].bsize / sizeof(int) - 1;
125         is->files[i].alloc_buf = (char *)
126             xmalloc (is->method->filecat[i].bsize);
127         is->files[i].no_writes = 0; /* clear statistics */
128         is->files[i].no_reads = 0;
129         is->files[i].no_skip_writes = 0;
130         is->files[i].no_allocated = 0;
131         is->files[i].no_released = 0;
132         is->files[i].no_remap = 0;
133         is->files[i].no_forward = 0;
134         is->files[i].no_backward = 0;
135         is->files[i].sum_forward = 0;
136         is->files[i].sum_backward = 0;
137         is->files[i].no_next = 0;
138         is->files[i].no_prev = 0;
139         is->files[i].no_op_nodiff=0;
140         is->files[i].no_op_intdiff=0;
141         is->files[i].no_op_extdiff=0;
142         is->files[i].no_fbuilds=0;   
143         is->files[i].no_appds=0;     
144         is->files[i].no_merges=0;    
145         is->files[i].no_remerges=0;  
146
147         init_fc (is, i);
148     }
149     return is;
150 }
151
152 int isamd_block_used (ISAMD is, int type)
153 {
154     if (type < 0 || type >= is->no_files)
155         return -1;
156     return is->files[type].head.lastblock-1;
157 }
158
159 int isamd_block_size (ISAMD is, int type)
160 {
161     ISAMD_filecat filecat = is->method->filecat;
162     if (type < 0 || type >= is->no_files)
163         return -1;
164     return filecat[type].bsize;
165 }
166
167 int isamd_close (ISAMD is)
168 {
169     int i;
170
171     if (is->method->debug>0)
172     {
173         logf (LOG_LOG, "isamd statistics");
174         logf (LOG_LOG, "f      nxt    forw   mid-f    prev   backw   mid-b");
175         for (i = 0; i<is->no_files; i++)
176             logf (LOG_LOG, "%d%8d%8d%8.1f%8d%8d%8.1f",i,
177                   is->files[i].no_next,
178                   is->files[i].no_forward,
179                   is->files[i].no_forward ?
180                   (double) is->files[i].sum_forward/is->files[i].no_forward
181                   : 0.0,
182                   is->files[i].no_prev,
183                   is->files[i].no_backward,
184                   is->files[i].no_backward ?
185                   (double) is->files[i].sum_backward/is->files[i].no_backward
186                   : 0.0);
187     }
188     if (is->method->debug>0)
189         logf (LOG_LOG, "f  writes   reads skipped   alloc released ");
190     for (i = 0; i<is->no_files; i++)
191     {
192         release_fc (is, i);
193         assert (is->files[i].bf);
194         if (is->files[i].head_is_dirty)
195             bf_write (is->files[i].bf, 0, 0, sizeof(ISAMD_head),
196                  &is->files[i].head);
197         if (is->method->debug>0)
198             logf (LOG_LOG, "%d%8d%8d%8d%8d%8d",i,
199                   is->files[i].no_writes,
200                   is->files[i].no_reads,
201                   is->files[i].no_skip_writes,
202                   is->files[i].no_allocated,
203                   is->files[i].no_released);
204         xfree (is->files[i].fc_list);
205         flush_block (is, i);
206         bf_close (is->files[i].bf);
207     }
208     
209     if (is->method->debug>0) 
210     {
211         logf (LOG_LOG, "f   opens  simple     int     ext");
212         for (i = 0; i<is->no_files; i++)
213         {
214             logf (LOG_LOG, "%d%8d%8d%8d%8d",i,
215                   is->files[i].no_op_nodiff+
216                   is->files[i].no_op_intdiff+
217                   is->files[i].no_op_extdiff,
218                   is->files[i].no_op_nodiff,
219                   is->files[i].no_op_intdiff,
220                   is->files[i].no_op_extdiff);
221         }
222         logf (LOG_LOG, "    build  append   merge   remrg");
223         logf (LOG_LOG, "=%8d%8d%8d%8d",
224                   is->files[0].no_fbuilds,
225                   is->files[0].no_appds,
226                   is->files[0].no_merges,
227                   is->files[0].no_remerges);
228     }
229     xfree (is->files);
230     xfree (is->method);
231     xfree (is);
232     return 0;
233 }
234
235 int isamd_read_block (ISAMD is, int cat, int pos, char *dst)
236 {
237     ++(is->files[cat].no_reads);
238     if (is->method->debug > 6)
239         logf (LOG_LOG, "isamd: read_block %d %d", cat, pos);
240     return bf_read (is->files[cat].bf, pos, 0, 0, dst);
241 }
242
243 int isamd_write_block (ISAMD is, int cat, int pos, char *src)
244 {
245     ++(is->files[cat].no_writes);
246     if (is->method->debug > 6)
247         logf (LOG_LOG, "isamd: write_block %d %d", cat, pos);
248     return bf_write (is->files[cat].bf, pos, 0, 0, src);
249 }
250
251 int isamd_write_dblock (ISAMD is, int cat, int pos, char *src,
252                       int nextpos, int offset)
253 {
254     ISAMD_BLOCK_SIZE size = offset + ISAMD_BLOCK_OFFSET_N;
255     if (is->method->debug > 4)
256         logf (LOG_LOG, "isamd: write_dblock. size=%d nextpos=%d",
257               (int) size, nextpos);
258     src -= ISAMD_BLOCK_OFFSET_N;
259     assert( ISAMD_BLOCK_OFFSET_N == sizeof(int)+sizeof(int) );
260     memcpy (src, &nextpos, sizeof(int));
261     memcpy (src + sizeof(int), &size, sizeof(size));
262     return isamd_write_block (is, cat, pos, src);
263 }
264
265 #if ISAMD_FREELIST_CHUNK
266 static void flush_block (ISAMD is, int cat)
267 {
268     char *abuf = is->files[cat].alloc_buf;
269     int block = is->files[cat].head.freelist;
270     if (block && is->files[cat].alloc_entries_num)
271     {
272         memcpy (abuf, &is->files[cat].alloc_entries_num, sizeof(int));
273         bf_write (is->files[cat].bf, block, 0, 0, abuf);
274         is->files[cat].alloc_entries_num = 0;
275     }
276     xfree (abuf);
277 }
278
279 static int alloc_block (ISAMD is, int cat)
280 {
281     int block = is->files[cat].head.freelist;
282     char *abuf = is->files[cat].alloc_buf;
283
284     (is->files[cat].no_allocated)++;
285
286     if (!block)
287     {
288         block = (is->files[cat].head.lastblock)++;   /* no free list */
289         is->files[cat].head_is_dirty = 1;
290     }
291     else
292     {
293         if (!is->files[cat].alloc_entries_num) /* read first time */
294         {
295             bf_read (is->files[cat].bf, block, 0, 0, abuf);
296             memcpy (&is->files[cat].alloc_entries_num, abuf,
297                     sizeof(is->files[cat].alloc_entries_num));
298             assert (is->files[cat].alloc_entries_num > 0);
299         }
300         /* have some free blocks now */
301         assert (is->files[cat].alloc_entries_num > 0);
302         is->files[cat].alloc_entries_num--;
303         if (!is->files[cat].alloc_entries_num)  /* last one in block? */
304         {
305             memcpy (&is->files[cat].head.freelist, abuf + sizeof(int),
306                     sizeof(int));
307             is->files[cat].head_is_dirty = 1;
308
309             if (is->files[cat].head.freelist)
310             {
311                 bf_read (is->files[cat].bf, is->files[cat].head.freelist,
312                          0, 0, abuf);
313                 memcpy (&is->files[cat].alloc_entries_num, abuf,
314                         sizeof(is->files[cat].alloc_entries_num));
315                 assert (is->files[cat].alloc_entries_num);
316             }
317         }
318         else
319             memcpy (&block, abuf + sizeof(int) + sizeof(int) *
320                     is->files[cat].alloc_entries_num, sizeof(int));
321     }
322     return block;
323 }
324
325 static void release_block (ISAMD is, int cat, int pos)
326 {
327     char *abuf = is->files[cat].alloc_buf;
328     int block = is->files[cat].head.freelist;
329
330     (is->files[cat].no_released)++;
331
332     if (block && !is->files[cat].alloc_entries_num) /* must read block */
333     {
334         bf_read (is->files[cat].bf, block, 0, 0, abuf);
335         memcpy (&is->files[cat].alloc_entries_num, abuf,
336                 sizeof(is->files[cat].alloc_entries_num));
337         assert (is->files[cat].alloc_entries_num > 0);
338     }
339     assert (is->files[cat].alloc_entries_num <= is->files[cat].alloc_entries_max);
340     if (is->files[cat].alloc_entries_num == is->files[cat].alloc_entries_max)
341     {
342         assert (block);
343         memcpy (abuf, &is->files[cat].alloc_entries_num, sizeof(int));
344         bf_write (is->files[cat].bf, block, 0, 0, abuf);
345         is->files[cat].alloc_entries_num = 0;
346     }
347     if (!is->files[cat].alloc_entries_num) /* make new buffer? */
348     {
349         memcpy (abuf + sizeof(int), &block, sizeof(int));
350         is->files[cat].head.freelist = pos;
351         is->files[cat].head_is_dirty = 1; 
352     }
353     else
354     {
355         memcpy (abuf + sizeof(int) +
356                 is->files[cat].alloc_entries_num*sizeof(int),
357                 &pos, sizeof(int));
358     }
359     is->files[cat].alloc_entries_num++;
360 }
361 #else
362 static void flush_block (ISAMD is, int cat)
363 {
364     char *abuf = is->files[cat].alloc_buf;
365     xfree (abuf);
366 }
367
368 static int alloc_block (ISAMD is, int cat)
369 {
370     int block;
371     char buf[sizeof(int)];
372
373     is->files[cat].head_is_dirty = 1;
374     (is->files[cat].no_allocated)++;
375     if ((block = is->files[cat].head.freelist))
376     {
377         bf_read (is->files[cat].bf, block, 0, sizeof(int), buf);
378         memcpy (&is->files[cat].head.freelist, buf, sizeof(int));
379     }
380     else
381         block = (is->files[cat].head.lastblock)++;
382     return block;
383 }
384
385 static void release_block (ISAMD is, int cat, int pos)
386 {
387     char buf[sizeof(int)];
388    
389     (is->files[cat].no_released)++;
390     is->files[cat].head_is_dirty = 1; 
391     memcpy (buf, &is->files[cat].head.freelist, sizeof(int));
392     is->files[cat].head.freelist = pos;
393     bf_write (is->files[cat].bf, pos, 0, sizeof(int), buf);
394 }
395 #endif
396
397 int isamd_alloc_block (ISAMD is, int cat)
398 {
399     int block = 0;
400
401     if (is->files[cat].fc_list)
402     {
403         int j, nb;
404         for (j = 0; j < is->files[cat].fc_max; j++)
405             if ((nb = is->files[cat].fc_list[j]) && (!block || nb < block))
406             {
407                 is->files[cat].fc_list[j] = 0;
408                 block = nb;
409                 break;
410             }
411     }
412     if (!block)
413         block = alloc_block (is, cat);
414     if (is->method->debug > 4)
415         logf (LOG_LOG, "isamd: alloc_block in cat %d: %d", cat, block);
416     return block;
417 }
418
419 void isamd_release_block (ISAMD is, int cat, int pos)
420 {
421     if (is->method->debug > 4)
422         logf (LOG_LOG, "isamd: release_block in cat %d: %d", cat, pos);
423     assert(pos!=0);
424     
425     if (is->files[cat].fc_list)
426     {
427         int j;
428         for (j = 0; j<is->files[cat].fc_max; j++)
429             if (!is->files[cat].fc_list[j])
430             {
431                 is->files[cat].fc_list[j] = pos;
432                 return;
433             }
434     }
435     release_block (is, cat, pos);
436 }
437
438 static void init_fc (ISAMD is, int cat)
439 {
440     int j = 100;
441         
442     is->files[cat].fc_max = j;
443     is->files[cat].fc_list = (int *)
444         xmalloc (sizeof(*is->files[0].fc_list) * j);
445     while (--j >= 0)
446         is->files[cat].fc_list[j] = 0;
447 }
448
449 static void release_fc (ISAMD is, int cat)
450 {
451     int b, j = is->files[cat].fc_max;
452
453     while (--j >= 0)
454         if ((b = is->files[cat].fc_list[j]))
455         {
456             release_block (is, cat, b);
457             is->files[cat].fc_list[j] = 0;
458         }
459 }
460
461 void isamd_pp_close (ISAMD_PP pp)
462 {
463     ISAMD is = pp->is;
464
465     (*is->method->code_stop)(ISAMD_DECODE, pp->decodeClientData);
466     isamd_free_diffs(pp);  /* see merge-d.h */
467     xfree (pp->buf);
468     xfree (pp);
469     if (is->method->debug > 5)
470        logf (LOG_LOG, "isamd_pp_close %p %d=%d:%d  sz=%d n=%d=%d:%d",
471              pp, isamd_addr(pp->pos, pp->cat), pp->cat, pp->pos, pp->size, 
472              pp->next, isamd_type(pp->next), isamd_block(pp->next) );
473 }
474
475
476
477 ISAMD_PP isamd_pp_open (ISAMD is, ISAMD_P ipos)
478 {
479     ISAMD_PP pp = (ISAMD_PP) xmalloc (sizeof(*pp));
480     char *src;
481     int sz = is->method->filecat[is->max_cat].bsize;
482                  /* always allocate for the largest blocks, saves trouble */
483    
484     pp->cat = isamd_type(ipos);
485     pp->pos = isamd_block(ipos); 
486
487     src = pp->buf = (char *) xmalloc (sz);
488     memset(src,'\0',sz); /* clear the buffer, for new blocks */
489     
490     pp->next = 0;
491     pp->size = 0;
492     pp->offset = 0;
493     pp->is = is;
494     pp->decodeClientData = (*is->method->code_start)(ISAMD_DECODE);
495     pp->numKeys = 0;
496     pp->diffs=0;
497   
498     pp->diffbuf=0;
499     pp->diffinfo=0;
500     
501     if (pp->pos)
502     {
503         src = pp->buf;
504         isamd_read_block (is, pp->cat, pp->pos, src);
505         memcpy (&pp->next, src, sizeof(pp->next));
506         src += sizeof(pp->next);
507         memcpy (&pp->size, src, sizeof(pp->size));
508         src += sizeof(pp->size);
509         memcpy (&pp->numKeys, src, sizeof(pp->numKeys));
510         src += sizeof(pp->numKeys);
511         memcpy (&pp->diffs, src, sizeof(pp->diffs));
512         src += sizeof(pp->diffs);
513         assert (pp->next != pp->pos);
514         pp->offset = src - pp->buf; 
515         assert (pp->offset == ISAMD_BLOCK_OFFSET_1);
516         if (0==pp->diffs)
517            ++(is->files[pp->cat].no_op_nodiff);
518         else
519            if(pp->diffs&1)
520                ++(is->files[pp->cat].no_op_extdiff);
521            else
522                ++(is->files[pp->cat].no_op_intdiff);
523     }
524     if (is->method->debug > 5)
525        logf (LOG_LOG, "isamd_pp_open  %p %d=%d:%d  sz=%d n=%d=%d:%d",
526              pp, isamd_addr(pp->pos, pp->cat), pp->cat, pp->pos, pp->size, 
527              pp->next, isamd_type(pp->next), isamd_block(pp->next) );
528     
529       
530     return pp;
531 }
532
533
534
535 void isamd_buildfirstblock(ISAMD_PP pp){
536   char *dst=pp->buf;
537   assert(pp->buf);
538   assert(pp->next != pp->pos); 
539   memcpy(dst, &pp->next, sizeof(pp->next) );
540   dst += sizeof(pp->next);
541   memcpy(dst, &pp->size,sizeof(pp->size));
542   dst += sizeof(pp->size);
543   memcpy(dst, &pp->numKeys, sizeof(pp->numKeys));
544   dst += sizeof(pp->numKeys);
545   memcpy(dst, &pp->diffs, sizeof(pp->diffs));
546   dst += sizeof(pp->diffs);  
547   assert (dst - pp->buf  == ISAMD_BLOCK_OFFSET_1);
548   if (pp->is->method->debug > 5)
549      logf (LOG_LOG, "isamd: first: sz=%d  p=%d/%d>%d/%d nk=%d d=%d",
550            pp->size, 
551            pp->cat, pp->pos, 
552            isamd_type(pp->next), isamd_block(pp->next),
553            pp->numKeys, pp->diffs);
554 }
555
556 void isamd_buildlaterblock(ISAMD_PP pp){
557   char *dst=pp->buf;
558   assert(pp->buf);
559   assert(pp->next != isamd_addr(pp->pos,pp->cat)); 
560   memcpy(dst, &pp->next, sizeof(pp->next) );
561   dst += sizeof(pp->next);
562   memcpy(dst, &pp->size,sizeof(pp->size));
563   dst += sizeof(pp->size);
564   assert (dst - pp->buf  == ISAMD_BLOCK_OFFSET_N);
565   if (pp->is->method->debug > 5)
566      logf (LOG_LOG, "isamd: l8r: sz=%d  p=%d/%d>%d/%d",
567            pp->size, 
568            pp->pos, pp->cat, 
569            isamd_block(pp->next), isamd_type(pp->next) );
570 }
571
572
573
574 /* returns non-zero if item could be read; 0 otherwise */
575 int isamd_pp_read (ISAMD_PP pp, void *buf)
576 {
577     return isamd_read_item (pp, (char **) &buf);
578     /* note: isamd_read_item is in merge-d.c, because it is so */
579     /* convoluted with the merge process */
580 }
581
582 /* read one main item from file - decode and store it in *dst.
583    Does not worry about diffs
584    Returns
585      0 if end-of-file
586      1 if item could be read ok
587 */
588 int isamd_read_main_item (ISAMD_PP pp, char **dst)
589 {
590     ISAMD is = pp->is;
591     char *src = pp->buf + pp->offset;
592     int newcat;
593
594     if (pp->offset >= pp->size)
595     {
596         if (!pp->next)
597         {
598             pp->pos = 0;
599             return 0; /* end of file */
600         }
601         if (pp->next > pp->pos)
602         {
603             if (pp->next == pp->pos + 1)
604                 is->files[pp->cat].no_next++;
605             else
606             {
607                 is->files[pp->cat].no_forward++;
608                 is->files[pp->cat].sum_forward += pp->next - pp->pos;
609             }
610         }
611         else
612         {
613             if (pp->next + 1 == pp->pos)
614                 is->files[pp->cat].no_prev++;
615             else
616             {
617                 is->files[pp->cat].no_backward++;
618                 is->files[pp->cat].sum_backward += pp->pos - pp->next;
619             }
620         }
621         /* out new block position */
622         newcat = isamd_type(pp->next);
623         pp->pos = isamd_block(pp->next);
624         pp->cat = isamd_type(pp->next);
625         
626         src = pp->buf;
627         /* read block and save 'next' and 'size' entry */
628         isamd_read_block (is, pp->cat, pp->pos, src);
629         memcpy (&pp->next, src, sizeof(pp->next));
630         src += sizeof(pp->next);
631         memcpy (&pp->size, src, sizeof(pp->size));
632         src += sizeof(pp->size);
633         /* assume block is non-empty */
634         assert (src - pp->buf == ISAMD_BLOCK_OFFSET_N);
635         assert (pp->next != isamd_addr(pp->pos,pp->cat));
636         (*is->method->code_reset)(pp->decodeClientData);
637         (*is->method->code_item)(ISAMD_DECODE, pp->decodeClientData, dst, &src);
638         pp->offset = src - pp->buf; 
639         if (is->method->debug > 4)
640             logf (LOG_LOG, "isamd: read_block size=%d %d %d next=%d",
641                  pp->size, pp->cat, pp->pos, pp->next);
642         return 2;
643     }
644     (*is->method->code_item)(ISAMD_DECODE, pp->decodeClientData, dst, &src);
645     pp->offset = src - pp->buf; 
646     return 1;
647 }
648
649 int isamd_pp_num (ISAMD_PP pp)
650 {
651     return pp->numKeys;
652 }
653
654 static char *hexdump(unsigned char *p, int len, char *buff) {
655   static char localbuff[128];
656   char bytebuff[8];
657   if (!buff) buff=localbuff;
658   *buff='\0';
659   while (len--) {
660     sprintf(bytebuff,"%02x",*p);
661     p++;
662     strcat(buff,bytebuff);
663     if (len) strcat(buff," ");
664   }
665   return buff;
666 }
667
668
669 void isamd_pp_dump (ISAMD is, ISAMD_P ipos)
670 {
671   ISAMD_PP pp;
672   ISAMD_P oldaddr=0;
673   struct it_key key;
674   int i,n;
675   int occur =0;
676   int oldoffs;
677   char hexbuff[64];
678   
679   logf(LOG_LOG,"dumping isamd block %d (%d:%d)",
680                   (int)ipos, isamd_type(ipos), isamd_block(ipos) );
681   pp=isamd_pp_open(is,ipos);
682   logf(LOG_LOG,"numKeys=%d,  ofs=%d d=%d",
683        pp->numKeys, 
684        pp->offset, pp->diffs);
685   oldoffs= pp->offset;
686   while(isamd_pp_read(pp, &key))
687   {
688      if (oldaddr != isamd_addr(pp->pos,pp->cat) )
689      {
690         oldaddr = isamd_addr(pp->pos,pp->cat); 
691         logf(LOG_LOG,"block %d (%d:%d) sz=%d nx=%d (%d:%d) ofs=%d",
692                   isamd_addr(pp->pos,pp->cat), 
693                   pp->cat, pp->pos, pp->size,
694                   pp->next, isamd_type(pp->next), isamd_block(pp->next),
695                   pp->offset);
696         i=0;      
697         while (i<pp->size) {
698           n=pp->size-i;
699           if (n>8) n=8;
700           logf(LOG_LOG,"  %05x: %s",i,hexdump(pp->buf+i,n,hexbuff));
701           i+=n;
702         }
703         if (oldoffs >  ISAMD_BLOCK_OFFSET_N)
704            oldoffs=ISAMD_BLOCK_OFFSET_N;
705      } /* new block */
706      occur++;
707      logf (LOG_LOG,"    got %d:%d=%x:%x from %s at %d=%x",
708                   key.sysno, key.seqno,
709                   key.sysno, key.seqno,
710                   hexdump(pp->buf+oldoffs, pp->offset-oldoffs, hexbuff),
711                   oldoffs, oldoffs);
712      oldoffs = pp->offset;
713   }
714   /*!*/ /*TODO: dump diffs too!!! */
715   isamd_pp_close(pp);
716 } /* dump */
717
718 /*
719  * $Log: isamd.c,v $
720  * Revision 1.11  1999-08-25 18:09:24  heikki
721  * Starting to optimize
722  *
723  * Revision 1.10  1999/08/24 13:17:42  heikki
724  * Block sizes, comments
725  *
726  * Revision 1.9  1999/08/20 12:25:58  heikki
727  * Statistics in isamd
728  *
729  * Revision 1.8  1999/08/18 13:28:16  heikki
730  * Set log levels to decent values
731  *
732  * Revision 1.6  1999/08/17 19:44:25  heikki
733  * Fixed memory leaks
734  *
735  * Revision 1.4  1999/08/04 14:21:18  heikki
736  * isam-d seems to be working.
737  *
738  * Revision 1.3  1999/07/21 14:24:50  heikki
739  * isamd write and read functions ok, except when diff block full.
740  * (merge not yet done)
741  *
742  * Revision 1.1  1999/07/14 12:34:43  heikki
743  * Copied from isamh, starting to change things...
744  *
745  *
746  */