isamb work
[idzebra-moved-to-github.git] / index / kinput.c
1 /*
2  * Copyright (C) 1994-2002, Index Data
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
5  *
6  * $Id: kinput.c,v 1.49 2002-04-16 22:31:42 adam Exp $
7  *
8  * Bugs
9  *  - Allocates a lot of memory for the merge process, but never releases it.
10  *    Doesn't matter, as the program terminates soon after.  
11  
12  */
13  
14 #include <fcntl.h>
15 #ifdef WIN32
16 #include <io.h>
17 #else
18 #include <unistd.h>
19 #endif
20 #include <stdlib.h>
21 #include <string.h>
22 #include <stdio.h>
23 #include <assert.h>
24
25 #include "index.h"
26
27 #define KEY_SIZE (1+sizeof(struct it_key))
28 #define INP_NAME_MAX 768
29 #define INP_BUF_START 60000
30 #define INP_BUF_ADD  400000
31
32
33 struct key_file {
34     int   no;            /* file no */
35     off_t offset;        /* file offset */
36     unsigned char *buf;  /* buffer block */
37     size_t buf_size;     /* number of read bytes in block */
38     size_t chunk;        /* number of bytes allocated */
39     size_t buf_ptr;      /* current position in buffer */
40     char *prev_name;     /* last word read */
41     int   sysno;         /* last sysno */
42     int   seqno;         /* last seqno */
43     off_t length;        /* length of file */
44                          /* handler invoked in each read */
45     void (*readHandler)(struct key_file *keyp, void *rinfo);
46     void *readInfo;
47     Res res;
48 };
49
50 void getFnameTmp (Res res, char *fname, int no)
51 {
52     const char *pre;
53     
54     pre = res_get_def (res, "keyTmpDir", ".");
55     sprintf (fname, "%s/key%d.tmp", pre, no);
56 }
57
58 void extract_get_fname_tmp (ZebraHandle zh, char *fname, int no)
59 {
60     const char *pre;
61     
62     pre = res_get_def (zh->res, "keyTmpDir", ".");
63     sprintf (fname, "%s/key%d.tmp", pre, no);
64 }
65
66 void key_file_chunk_read (struct key_file *f)
67 {
68     int nr = 0, r = 0, fd;
69     char fname[1024];
70     getFnameTmp (f->res, fname, f->no);
71     fd = open (fname, O_BINARY|O_RDONLY);
72
73     f->buf_ptr = 0;
74     f->buf_size = 0;
75     if (fd == -1)
76     {
77         logf (LOG_WARN|LOG_ERRNO, "cannot open %s", fname);
78         return ;
79     }
80     if (!f->length)
81     {
82         if ((f->length = lseek (fd, 0L, SEEK_END)) == (off_t) -1)
83         {
84             logf (LOG_WARN|LOG_ERRNO, "cannot seek %s", fname);
85             close (fd);
86             return ;
87         }
88     }
89     if (lseek (fd, f->offset, SEEK_SET) == -1)
90     {
91         logf (LOG_WARN|LOG_ERRNO, "cannot seek %s", fname);
92         close(fd);
93         return ;
94     }
95     while (f->chunk - nr > 0)
96     {
97         r = read (fd, f->buf + nr, f->chunk - nr);
98         if (r <= 0)
99             break;
100         nr += r;
101     }
102     if (r == -1)
103     {
104         logf (LOG_WARN|LOG_ERRNO, "read of %s", fname);
105         close (fd);
106         return;
107     }
108     f->buf_size = nr;
109     if (f->readHandler)
110         (*f->readHandler)(f, f->readInfo);
111     close (fd);
112 }
113
114 void key_file_destroy (struct key_file *f)
115 {
116     xfree (f->buf);
117     xfree (f->prev_name);
118     xfree (f);
119 }
120
121 struct key_file *key_file_init (int no, int chunk, Res res)
122 {
123     struct key_file *f;
124
125     f = (struct key_file *) xmalloc (sizeof(*f));
126     f->res = res;
127     f->sysno = 0;
128     f->seqno = 0;
129     f->no = no;
130     f->chunk = chunk;
131     f->offset = 0;
132     f->length = 0;
133     f->readHandler = NULL;
134     f->buf = (unsigned char *) xmalloc (f->chunk);
135     f->prev_name = (char *) xmalloc (INP_NAME_MAX);
136     *f->prev_name = '\0';
137     key_file_chunk_read (f);
138     return f;
139 }
140
141 int key_file_getc (struct key_file *f)
142 {
143     if (f->buf_ptr < f->buf_size)
144         return f->buf[(f->buf_ptr)++];
145     if (f->buf_size < f->chunk)
146         return EOF;
147     f->offset += f->buf_size;
148     key_file_chunk_read (f);
149     if (f->buf_ptr < f->buf_size)
150         return f->buf[(f->buf_ptr)++];
151     else
152         return EOF;
153 }
154
155 int key_file_decode (struct key_file *f)
156 {
157     int c, d;
158
159     c = key_file_getc (f);
160     switch (c & 192) 
161     {
162     case 0:
163         d = c;
164         break;
165     case 64:
166         d = ((c&63) << 8) + (key_file_getc (f) & 0xff);
167         break;
168     case 128:
169         d = ((c&63) << 8) + (key_file_getc (f) & 0xff);
170         d = (d << 8) + (key_file_getc (f) & 0xff);
171         break;
172     case 192:
173         d = ((c&63) << 8) + (key_file_getc (f) & 0xff);
174         d = (d << 8) + (key_file_getc (f) & 0xff);
175         d = (d << 8) + (key_file_getc (f) & 0xff);
176         break;
177     }
178     return d;
179 }
180
181 int key_file_read (struct key_file *f, char *key)
182 {
183     int i, d, c;
184     struct it_key itkey;
185
186     c = key_file_getc (f);
187     if (c == 0)
188     {
189         strcpy (key, f->prev_name);
190         i = 1+strlen (key);
191     }
192     else if (c == EOF)
193         return 0;
194     else
195     {
196         i = 0;
197         key[i++] = c;
198         while ((key[i++] = key_file_getc (f)))
199             ;
200         strcpy (f->prev_name, key);
201         f->sysno = 0;
202     }
203     d = key_file_decode (f);
204     key[i++] = d & 1;
205     d = d >> 1;
206     itkey.sysno = d + f->sysno;
207     if (d) 
208     {
209         f->sysno = itkey.sysno;
210         f->seqno = 0;
211     }
212     d = key_file_decode (f);
213     itkey.seqno = d + f->seqno;
214     f->seqno = itkey.seqno;
215     memcpy (key + i, &itkey, sizeof(struct it_key));
216     return i + sizeof (struct it_key);
217 }
218
219 struct heap_info {
220     struct {
221         struct key_file **file;
222         char   **buf;
223     } info;
224     int    heapnum;
225     int    *ptr;
226     int    (*cmp)(const void *p1, const void *p2);
227     struct zebra_register *reg;
228
229     int no_diffs;
230     int no_updates;
231     int no_deletions;
232     int no_insertions;
233     int no_iterations;
234 };
235
236 struct heap_info *key_heap_init (int nkeys,
237                                  int (*cmp)(const void *p1, const void *p2))
238 {
239     struct heap_info *hi;
240     int i;
241
242     hi = (struct heap_info *) xmalloc (sizeof(*hi));
243     hi->info.file = (struct key_file **)
244         xmalloc (sizeof(*hi->info.file) * (1+nkeys));
245     hi->info.buf = (char **) xmalloc (sizeof(*hi->info.buf) * (1+nkeys));
246     hi->heapnum = 0;
247     hi->ptr = (int *) xmalloc (sizeof(*hi->ptr) * (1+nkeys));
248     hi->cmp = cmp;
249     for (i = 0; i<= nkeys; i++)
250     {
251         hi->ptr[i] = i;
252         hi->info.buf[i] = (char *) xmalloc (INP_NAME_MAX);
253     }
254     hi->no_diffs = 0;
255     hi->no_diffs = 0;
256     hi->no_updates = 0;
257     hi->no_deletions = 0;
258     hi->no_insertions = 0;
259     hi->no_iterations = 0;
260     return hi;
261 }
262
263 void key_heap_destroy (struct heap_info *hi, int nkeys)
264 {
265     int i;
266     yaz_log (LOG_LOG, "key_heap_destroy");
267     for (i = 0; i<=nkeys; i++)
268         xfree (hi->info.buf[i]);
269     
270     xfree (hi->info.buf);
271     xfree (hi->ptr);
272     xfree (hi->info.file);
273     xfree (hi);
274 }
275
276 static void key_heap_swap (struct heap_info *hi, int i1, int i2)
277 {
278     int swap;
279
280     swap = hi->ptr[i1];
281     hi->ptr[i1] = hi->ptr[i2];
282     hi->ptr[i2] = swap;
283 }
284
285
286 static void key_heap_delete (struct heap_info *hi)
287 {
288     int cur = 1, child = 2;
289
290     assert (hi->heapnum > 0);
291
292     key_heap_swap (hi, 1, hi->heapnum);
293     hi->heapnum--;
294     while (child <= hi->heapnum) {
295         if (child < hi->heapnum &&
296             (*hi->cmp)(&hi->info.buf[hi->ptr[child]],
297                        &hi->info.buf[hi->ptr[child+1]]) > 0)
298             child++;
299         if ((*hi->cmp)(&hi->info.buf[hi->ptr[cur]],
300                        &hi->info.buf[hi->ptr[child]]) > 0)
301         {            
302             key_heap_swap (hi, cur, child);
303             cur = child;
304             child = 2*cur;
305         }
306         else
307             break;
308     }
309 }
310
311 static void key_heap_insert (struct heap_info *hi, const char *buf, int nbytes,
312                              struct key_file *kf)
313 {
314     int cur, parent;
315
316     cur = ++(hi->heapnum);
317     memcpy (hi->info.buf[hi->ptr[cur]], buf, nbytes);
318     hi->info.file[hi->ptr[cur]] = kf;
319
320     parent = cur/2;
321     while (parent && (*hi->cmp)(&hi->info.buf[hi->ptr[parent]],
322                                 &hi->info.buf[hi->ptr[cur]]) > 0)
323     {
324         key_heap_swap (hi, cur, parent);
325         cur = parent;
326         parent = cur/2;
327     }
328 }
329
330 static int heap_read_one (struct heap_info *hi, char *name, char *key)
331 {
332     int n, r;
333     char rbuf[INP_NAME_MAX];
334     struct key_file *kf;
335
336     if (!hi->heapnum)
337         return 0;
338     n = hi->ptr[1];
339     strcpy (name, hi->info.buf[n]);
340     kf = hi->info.file[n];
341     r = strlen(name);
342     memcpy (key, hi->info.buf[n] + r+1, KEY_SIZE);
343     key_heap_delete (hi);
344     if ((r = key_file_read (kf, rbuf)))
345         key_heap_insert (hi, rbuf, r, kf);
346     hi->no_iterations++;
347     return 1;
348 }
349
350 struct heap_cread_info {
351     char prev_name[INP_NAME_MAX];
352     char cur_name[INP_NAME_MAX];
353     char *key;
354     struct heap_info *hi;
355     int mode;
356     int more;
357 };
358       
359 int heap_cread_item (void *vp, char **dst, int *insertMode)
360 {
361     struct heap_cread_info *p = (struct heap_cread_info *) vp;
362     struct heap_info *hi = p->hi;
363
364     if (p->mode == 1)
365     {
366         *insertMode = p->key[0];
367         memcpy (*dst, p->key+1, sizeof(struct it_key));
368         (*dst) += sizeof(struct it_key);
369         p->mode = 2;
370         return 1;
371     }
372     strcpy (p->prev_name, p->cur_name);
373     if (!(p->more = heap_read_one (hi, p->cur_name, p->key)))
374         return 0;
375     if (*p->cur_name && strcmp (p->cur_name, p->prev_name))
376     {
377         p->mode = 1;
378         return 0;
379     }
380     *insertMode = p->key[0];
381     memcpy (*dst, p->key+1, sizeof(struct it_key));
382     (*dst) += sizeof(struct it_key);
383     return 1;
384 }
385
386 int heap_inpc (struct heap_info *hi)
387 {
388     struct heap_cread_info hci;
389     ISAMC_I isamc_i = (ISAMC_I) xmalloc (sizeof(*isamc_i));
390
391     hci.key = (char *) xmalloc (KEY_SIZE);
392     hci.mode = 1;
393     hci.hi = hi;
394     hci.more = heap_read_one (hi, hci.cur_name, hci.key);
395
396     isamc_i->clientData = &hci;
397     isamc_i->read_item = heap_cread_item;
398
399     while (hci.more)
400     {
401         char this_name[INP_NAME_MAX];
402         ISAMC_P isamc_p, isamc_p2;
403         char *dict_info;
404
405         strcpy (this_name, hci.cur_name);
406         assert (hci.cur_name[1]);
407         hi->no_diffs++;
408         if ((dict_info = dict_lookup (hi->reg->dict, hci.cur_name)))
409         {
410             memcpy (&isamc_p, dict_info+1, sizeof(ISAMC_P));
411             isamc_p2 = isc_merge (hi->reg->isamc, isamc_p, isamc_i);
412             if (!isamc_p2)
413             {
414                 hi->no_deletions++;
415                 if (!dict_delete (hi->reg->dict, this_name))
416                     abort();
417             }
418             else 
419             {
420                 hi->no_updates++;
421                 if (isamc_p2 != isamc_p)
422                     dict_insert (hi->reg->dict, this_name,
423                                  sizeof(ISAMC_P), &isamc_p2);
424             }
425         } 
426         else
427         {
428             isamc_p = isc_merge (hi->reg->isamc, 0, isamc_i);
429             hi->no_insertions++;
430             dict_insert (hi->reg->dict, this_name, sizeof(ISAMC_P), &isamc_p);
431         }
432     }
433     xfree (isamc_i);
434     xfree (hci.key);
435     return 0;
436
437
438 int heap_inpb (struct heap_info *hi)
439 {
440     struct heap_cread_info hci;
441     ISAMC_I isamc_i = (ISAMC_I) xmalloc (sizeof(*isamc_i));
442
443     hci.key = (char *) xmalloc (KEY_SIZE);
444     hci.mode = 1;
445     hci.hi = hi;
446     hci.more = heap_read_one (hi, hci.cur_name, hci.key);
447
448     isamc_i->clientData = &hci;
449     isamc_i->read_item = heap_cread_item;
450
451     while (hci.more)
452     {
453         char this_name[INP_NAME_MAX];
454         ISAMC_P isamc_p, isamc_p2;
455         char *dict_info;
456
457         strcpy (this_name, hci.cur_name);
458         assert (hci.cur_name[1]);
459         hi->no_diffs++;
460         if ((dict_info = dict_lookup (hi->reg->dict, hci.cur_name)))
461         {
462             memcpy (&isamc_p, dict_info+1, sizeof(ISAMC_P));
463             isamc_p2 = isamb_merge (hi->reg->isamb, isamc_p, isamc_i);
464             if (!isamc_p2)
465             {
466                 hi->no_deletions++;
467                 if (!dict_delete (hi->reg->dict, this_name))
468                     abort();
469             }
470             else 
471             {
472                 hi->no_updates++;
473                 if (isamc_p2 != isamc_p)
474                     dict_insert (hi->reg->dict, this_name,
475                                  sizeof(ISAMC_P), &isamc_p2);
476             }
477         } 
478         else
479         {
480             isamc_p = isamb_merge (hi->reg->isamb, 0, isamc_i);
481             hi->no_insertions++;
482             dict_insert (hi->reg->dict, this_name, sizeof(ISAMC_P), &isamc_p);
483         }
484     }
485     xfree (isamc_i);
486     xfree (hci.key);
487     return 0;
488
489
490 int heap_inpd (struct heap_info *hi)
491 {
492     struct heap_cread_info hci;
493     ISAMD_I isamd_i = (ISAMD_I) xmalloc (sizeof(*isamd_i));
494
495     hci.key = (char *) xmalloc (KEY_SIZE);
496     hci.mode = 1;
497     hci.hi = hi;
498     hci.more = heap_read_one (hi, hci.cur_name, hci.key);
499
500     isamd_i->clientData = &hci;
501     isamd_i->read_item = heap_cread_item;
502
503     while (hci.more)
504     {
505         char this_name[INP_NAME_MAX];
506         ISAMD_P isamd_p, isamd_p2;
507         char *dict_info;
508
509         strcpy (this_name, hci.cur_name);
510         assert (hci.cur_name[1]);
511         hi->no_diffs++;
512         if ((dict_info = dict_lookup (hi->reg->dict, hci.cur_name)))
513         {
514             memcpy (&isamd_p, dict_info+1, sizeof(ISAMD_P));
515             isamd_p2 = isamd_append (hi->reg->isamd, isamd_p, isamd_i);
516             if (!isamd_p2)
517             {
518                 hi->no_deletions++;
519                 if (!dict_delete (hi->reg->dict, this_name))
520                     abort();
521             }
522             else 
523             {
524                 hi->no_updates++;
525                 if (isamd_p2 != isamd_p)
526                     dict_insert (hi->reg->dict, this_name,
527                                  sizeof(ISAMD_P), &isamd_p2);
528             }
529         } 
530         else
531         {
532             isamd_p = isamd_append (hi->reg->isamd, 0, isamd_i);
533             hi->no_insertions++;
534             dict_insert (hi->reg->dict, this_name, sizeof(ISAMD_P), &isamd_p);
535         }
536     }
537     xfree (isamd_i);
538     return 0;
539
540
541 int heap_inp (struct heap_info *hi)
542 {
543     char *info;
544     char next_name[INP_NAME_MAX];
545     char cur_name[INP_NAME_MAX];
546     int key_buf_size = INP_BUF_START;
547     int key_buf_ptr;
548     char *next_key;
549     char *key_buf;
550     int more;
551     
552     next_key = (char *) xmalloc (KEY_SIZE);
553     key_buf = (char *) xmalloc (key_buf_size);
554     more = heap_read_one (hi, cur_name, key_buf);
555     while (more)                   /* EOF ? */
556     {
557         int nmemb;
558         key_buf_ptr = KEY_SIZE;
559         while (1)
560         {
561             if (!(more = heap_read_one (hi, next_name, next_key)))
562                 break;
563             if (*next_name && strcmp (next_name, cur_name))
564                 break;
565             memcpy (key_buf + key_buf_ptr, next_key, KEY_SIZE);
566             key_buf_ptr += KEY_SIZE;
567             if (key_buf_ptr+(int) KEY_SIZE >= key_buf_size)
568             {
569                 char *new_key_buf;
570                 new_key_buf = (char *) xmalloc (key_buf_size + INP_BUF_ADD);
571                 memcpy (new_key_buf, key_buf, key_buf_size);
572                 key_buf_size += INP_BUF_ADD;
573                 xfree (key_buf);
574                 key_buf = new_key_buf;
575             }
576         }
577         hi->no_diffs++;
578         nmemb = key_buf_ptr / KEY_SIZE;
579         assert (nmemb * (int) KEY_SIZE == key_buf_ptr);
580         if ((info = dict_lookup (hi->reg->dict, cur_name)))
581         {
582             ISAM_P isam_p, isam_p2;
583             memcpy (&isam_p, info+1, sizeof(ISAM_P));
584             isam_p2 = is_merge (hi->reg->isam, isam_p, nmemb, key_buf);
585             if (!isam_p2)
586             {
587                 hi->no_deletions++;
588                 if (!dict_delete (hi->reg->dict, cur_name))
589                     abort ();
590             }
591             else 
592             {
593                 hi->no_updates++;
594                 if (isam_p2 != isam_p)
595                     dict_insert (hi->reg->dict, cur_name,
596                                  sizeof(ISAM_P), &isam_p2);
597             }
598         }
599         else
600         {
601             ISAM_P isam_p;
602             hi->no_insertions++;
603             isam_p = is_merge (hi->reg->isam, 0, nmemb, key_buf);
604             dict_insert (hi->reg->dict, cur_name, sizeof(ISAM_P), &isam_p);
605         }
606         memcpy (key_buf, next_key, KEY_SIZE);
607         strcpy (cur_name, next_name);
608     }
609     return 0;
610 }
611
612 int heap_inps (struct heap_info *hi)
613 {
614     struct heap_cread_info hci;
615     ISAMS_I isams_i = (ISAMS_I) xmalloc (sizeof(*isams_i));
616
617     hci.key = (char *) xmalloc (KEY_SIZE);
618     hci.mode = 1;
619     hci.hi = hi;
620     hci.more = heap_read_one (hi, hci.cur_name, hci.key);
621
622     isams_i->clientData = &hci;
623     isams_i->read_item = heap_cread_item;
624
625     while (hci.more)
626     {
627         char this_name[INP_NAME_MAX];
628         ISAMS_P isams_p;
629         char *dict_info;
630
631         strcpy (this_name, hci.cur_name);
632         assert (hci.cur_name[1]);
633         hi->no_diffs++;
634         if (!(dict_info = dict_lookup (hi->reg->dict, hci.cur_name)))
635         {
636             isams_p = isams_merge (hi->reg->isams, isams_i);
637             hi->no_insertions++;
638             dict_insert (hi->reg->dict, this_name, sizeof(ISAMS_P), &isams_p);
639         }
640         else
641         {
642             logf (LOG_FATAL, "isams doesn't support this kind of update");
643             break;
644         }
645     }
646     xfree (isams_i);
647     return 0;
648
649
650 struct progressInfo {
651     time_t   startTime;
652     time_t   lastTime;
653     off_t    totalBytes;
654     off_t    totalOffset;
655 };
656
657 void progressFunc (struct key_file *keyp, void *info)
658 {
659     struct progressInfo *p = (struct progressInfo *) info;
660     time_t now, remaining;
661
662     if (keyp->buf_size <= 0 || p->totalBytes <= 0)
663         return ;
664     time (&now);
665
666     if (now >= p->lastTime+10)
667     {
668         p->lastTime = now;
669         remaining = (time_t) ((now - p->startTime)*
670             ((double) p->totalBytes/p->totalOffset - 1.0));
671         if (remaining <= 130)
672             logf (LOG_LOG, "Merge %2.1f%% completed; %ld seconds remaining",
673                  (100.0*p->totalOffset) / p->totalBytes, (long) remaining);
674         else
675             logf (LOG_LOG, "Merge %2.1f%% completed; %ld minutes remaining",
676                  (100.0*p->totalOffset) / p->totalBytes, (long) remaining/60);
677     }
678     p->totalOffset += keyp->buf_size;
679 }
680
681 #ifndef R_OK
682 #define R_OK 4
683 #endif
684
685 void zebra_index_merge (ZebraHandle zh)
686 {
687     struct key_file **kf;
688     char rbuf[1024];
689     int i, r;
690     struct heap_info *hi;
691     struct progressInfo progressInfo;
692     int nkeys = zh->reg->key_file_no;
693     
694     if (nkeys < 0)
695     {
696         char fname[1024];
697         nkeys = 0;
698         while (1)
699         {
700             extract_get_fname_tmp  (zh, fname, nkeys+1);
701             if (access (fname, R_OK) == -1)
702                 break;
703             nkeys++;
704         }
705         if (!nkeys)
706             return ;
707     }
708     kf = (struct key_file **) xmalloc ((1+nkeys) * sizeof(*kf));
709     progressInfo.totalBytes = 0;
710     progressInfo.totalOffset = 0;
711     time (&progressInfo.startTime);
712     time (&progressInfo.lastTime);
713     for (i = 1; i<=nkeys; i++)
714     {
715         kf[i] = key_file_init (i, 8192, zh->res);
716         kf[i]->readHandler = progressFunc;
717         kf[i]->readInfo = &progressInfo;
718         progressInfo.totalBytes += kf[i]->length;
719         progressInfo.totalOffset += kf[i]->buf_size;
720     }
721     hi = key_heap_init (nkeys, key_qsort_compare);
722     hi->reg = zh->reg;
723     
724     for (i = 1; i<=nkeys; i++)
725         if ((r = key_file_read (kf[i], rbuf)))
726             key_heap_insert (hi, rbuf, r, kf[i]);
727     if (zh->reg->isams)
728         heap_inps (hi);
729     if (zh->reg->isamc)
730         heap_inpc (hi);
731     if (zh->reg->isam)
732         heap_inp (hi);
733     if (zh->reg->isamd)
734         heap_inpd (hi);
735     if (zh->reg->isamb)
736         heap_inpb (hi);
737         
738     for (i = 1; i<=nkeys; i++)
739     {
740         extract_get_fname_tmp  (zh, rbuf, i);
741         unlink (rbuf);
742     }
743     logf (LOG_LOG, "Iterations . . .%7d", hi->no_iterations);
744     logf (LOG_LOG, "Distinct words .%7d", hi->no_diffs);
745     logf (LOG_LOG, "Updates. . . . .%7d", hi->no_updates);
746     logf (LOG_LOG, "Deletions. . . .%7d", hi->no_deletions);
747     logf (LOG_LOG, "Insertions . . .%7d", hi->no_insertions);
748     zh->reg->key_file_no = 0;
749
750     key_heap_destroy (hi, nkeys);
751     for (i = 1; i<=nkeys; i++)
752         key_file_destroy (kf[i]);
753     xfree (kf);
754 }
755
756