* All rights reserved.
* Sebastian Hammer, Adam Dickmeiss, Heikki Levanto
*
- * $Id: kinput.c,v 1.45 2002-02-20 17:30:01 adam Exp $
+ * $Id: kinput.c,v 1.48 2002-04-05 08:46:26 adam Exp $
*
* Bugs
* - Allocates a lot of memory for the merge process, but never releases it.
#include <assert.h>
#include "index.h"
-#include "zserver.h"
#define KEY_SIZE (1+sizeof(struct it_key))
#define INP_NAME_MAX 768
{
const char *pre;
- pre = res_get_def (zh->service->res, "keyTmpDir", ".");
+ pre = res_get_def (zh->res, "keyTmpDir", ".");
sprintf (fname, "%s/key%d.tmp", pre, no);
}
close (fd);
}
+void key_file_destroy (struct key_file *f)
+{
+ xfree (f->buf);
+ xfree (f->prev_name);
+ xfree (f);
+}
+
struct key_file *key_file_init (int no, int chunk, Res res)
{
struct key_file *f;
int (*cmp)(const void *p1, const void *p2);
Dict dict;
ISAMS isams;
-#if ZMBOL
ISAM isam;
ISAMC isamc;
ISAMD isamd;
-#endif
};
struct heap_info *key_heap_init (int nkeys,
return hi;
}
+void key_heap_destroy (struct heap_info *hi, int nkeys)
+{
+ int i;
+ yaz_log (LOG_LOG, "key_heap_destroy");
+ for (i = 0; i<=nkeys; i++)
+ xfree (hi->info.buf[i]);
+
+ xfree (hi->info.buf);
+ xfree (hi->ptr);
+ xfree (hi->info.file);
+ xfree (hi);
+}
+
static void key_heap_swap (struct heap_info *hi, int i1, int i2)
{
int swap;
return 1;
}
-#if ZMBOL
int heap_inpc (struct heap_info *hi)
{
struct heap_cread_info hci;
return 0;
}
-#endif
-
int heap_inps (struct heap_info *hi)
{
struct heap_cread_info hci;
int i, r;
struct heap_info *hi;
struct progressInfo progressInfo;
- int nkeys = zh->key_file_no;
+ int nkeys = zh->reg->key_file_no;
if (nkeys < 0)
{
time (&progressInfo.lastTime);
for (i = 1; i<=nkeys; i++)
{
- kf[i] = key_file_init (i, 8192, zh->service->res);
+ kf[i] = key_file_init (i, 8192, zh->res);
kf[i]->readHandler = progressFunc;
kf[i]->readInfo = &progressInfo;
progressInfo.totalBytes += kf[i]->length;
progressInfo.totalOffset += kf[i]->buf_size;
}
hi = key_heap_init (nkeys, key_qsort_compare);
- hi->dict = zh->service->dict;
- hi->isams = zh->service->isams;
-#if ZMBOL
- hi->isam = zh->service->isam;
- hi->isamc = zh->service->isamc;
- hi->isamd = zh->service->isamd;
-#endif
+ hi->dict = zh->reg->dict;
+ hi->isams = zh->reg->isams;
+ hi->isam = zh->reg->isam;
+ hi->isamc = zh->reg->isamc;
+ hi->isamd = zh->reg->isamd;
for (i = 1; i<=nkeys; i++)
if ((r = key_file_read (kf[i], rbuf)))
key_heap_insert (hi, rbuf, r, kf[i]);
- if (zh->service->isams)
+ if (zh->reg->isams)
heap_inps (hi);
-#if ZMBOL
- else if (zh->service->isamc)
+ else if (zh->reg->isamc)
heap_inpc (hi);
- else if (zh->service->isam)
+ else if (zh->reg->isam)
heap_inp (hi);
- else if (zh->service->isamd)
+ else if (zh->reg->isamd)
heap_inpd (hi);
-#endif
for (i = 1; i<=nkeys; i++)
{
logf (LOG_LOG, "Updates. . . . .%7d", no_updates);
logf (LOG_LOG, "Deletions. . . .%7d", no_deletions);
logf (LOG_LOG, "Insertions . . .%7d", no_insertions);
- zh->key_file_no = 0;
-}
-
-void key_input (ZebraHandle zh, int nkeys, int cache, Res res)
-
-{
- struct key_file **kf;
- char rbuf[1024];
- int i, r;
- struct heap_info *hi;
- struct progressInfo progressInfo;
+ zh->reg->key_file_no = 0;
- if (nkeys < 0)
- {
- char fname[1024];
- nkeys = 0;
- while (1)
- {
- getFnameTmp (res, fname, nkeys+1);
- if (access (fname, R_OK) == -1)
- break;
- nkeys++;
- }
- if (!nkeys)
- return ;
- }
- kf = (struct key_file **) xmalloc ((1+nkeys) * sizeof(*kf));
- progressInfo.totalBytes = 0;
- progressInfo.totalOffset = 0;
- time (&progressInfo.startTime);
- time (&progressInfo.lastTime);
- for (i = 1; i<=nkeys; i++)
- {
- kf[i] = key_file_init (i, 8192, res);
- kf[i]->readHandler = progressFunc;
- kf[i]->readInfo = &progressInfo;
- progressInfo.totalBytes += kf[i]->length;
- progressInfo.totalOffset += kf[i]->buf_size;
- }
- hi = key_heap_init (nkeys, key_qsort_compare);
- hi->dict = zh->service->dict;
- hi->isams = zh->service->isams;
-#if ZMBOL
- hi->isam = zh->service->isam;
- hi->isamc = zh->service->isamc;
- hi->isamd = zh->service->isamd;
-#endif
-
- for (i = 1; i<=nkeys; i++)
- if ((r = key_file_read (kf[i], rbuf)))
- key_heap_insert (hi, rbuf, r, kf[i]);
- if (hi->isams)
- heap_inps (hi);
-#if ZMBOL
- else if (hi->isamc)
- heap_inpc (hi);
- else if (hi->isam)
- heap_inp (hi);
- else if (hi->isamd)
- heap_inpd (hi);
-#endif
-
+ key_heap_destroy (hi, nkeys);
for (i = 1; i<=nkeys; i++)
- {
- getFnameTmp (res, rbuf, i);
- unlink (rbuf);
- }
- logf (LOG_LOG, "Iterations . . .%7d", no_iterations);
- logf (LOG_LOG, "Distinct words .%7d", no_diffs);
- logf (LOG_LOG, "Updates. . . . .%7d", no_updates);
- logf (LOG_LOG, "Deletions. . . .%7d", no_deletions);
- logf (LOG_LOG, "Insertions . . .%7d", no_insertions);
-
- /* xmalloc_trav("unfreed"); while hunting leaks */
+ key_file_destroy (kf[i]);
+ xfree (kf);
}
+