X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Fkinput.c;h=c5605914fc382be0a5333aa21f69494b96587210;hb=10e178572346e8c5c3caaa43b803dd10c005cb5f;hp=eb7b251320ec7c39b998a25097211c498a37148d;hpb=2954746ef5c897ec5e651cc2c39eda878f1d5da5;p=idzebra-moved-to-github.git diff --git a/index/kinput.c b/index/kinput.c index eb7b251..c560591 100644 --- a/index/kinput.c +++ b/index/kinput.c @@ -1,10 +1,42 @@ /* - * Copyright (C) 1994-1996, Index Data I/S + * Copyright (C) 1994-1999, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: kinput.c,v $ - * Revision 1.23 1997-09-04 13:57:39 adam + * Revision 1.33 1999-05-15 14:36:38 adam + * Updated dictionary. Implemented "compression" of dictionary. + * + * Revision 1.32 1999/05/12 13:08:06 adam + * First version of ISAMS. + * + * Revision 1.31 1999/02/02 14:50:56 adam + * Updated WIN32 code specific sections. Changed header. + * + * Revision 1.30 1998/10/28 10:53:57 adam + * Added type cast to prevent warning. + * + * Revision 1.29 1998/06/11 15:41:39 adam + * Minor changes. + * + * Revision 1.28 1998/03/05 08:45:12 adam + * New result set model and modular ranking system. Moved towards + * descent server API. System information stored as "SGML" records. + * + * Revision 1.27 1998/02/17 10:32:52 adam + * Fixed bug: binary files weren't opened with flag b on NT. + * + * Revision 1.26 1998/01/29 13:39:13 adam + * Compress ISAM is default. + * + * Revision 1.25 1997/09/17 12:19:14 adam + * Zebra version corresponds to YAZ version 1.4. + * Changed Zebra server so that it doesn't depend on global common_resource. + * + * Revision 1.24 1997/09/09 13:38:07 adam + * Partial port to WIN95/NT. + * + * Revision 1.23 1997/09/04 13:57:39 adam * Added O_BINARY for open calls. * * Revision 1.22 1997/02/12 20:39:45 adam @@ -88,7 +120,11 @@ */ #include +#ifdef WIN32 +#include +#else #include +#endif #include #include #include @@ -133,7 +169,7 @@ void getFnameTmp (char *fname, int no) void key_file_chunk_read (struct key_file *f) { - int nr = 0, r, fd; + int nr = 0, r = 0, fd; char fname[1024]; getFnameTmp (fname, f->no); fd = open (fname, O_BINARY|O_RDONLY); @@ -282,6 +318,7 @@ struct heap_info { Dict dict; ISAM isam; ISAMC isamc; + ISAMS isams; }; struct heap_info *key_heap_init (int nkeys, @@ -434,7 +471,7 @@ int heap_inpc (struct heap_info *hi) char *dict_info; strcpy (this_name, hci.cur_name); - logf (LOG_DEBUG, "inserting %s", 1+hci.cur_name); + assert (hci.cur_name[1]); no_diffs++; if ((dict_info = dict_lookup (hi->dict, hci.cur_name))) { @@ -465,6 +502,42 @@ int heap_inpc (struct heap_info *hi) return 0; } +int heap_inps (struct heap_info *hi) +{ + struct heap_cread_info hci; + ISAMS_I isams_i = xmalloc (sizeof(*isams_i)); + + hci.key = xmalloc (KEY_SIZE); + hci.mode = 1; + hci.hi = hi; + hci.more = heap_read_one (hi, hci.cur_name, hci.key); + + isams_i->clientData = &hci; + isams_i->read_item = heap_cread_item; + + while (hci.more) + { + char this_name[INP_NAME_MAX]; + ISAMS_P isams_p; + char *dict_info; + + strcpy (this_name, hci.cur_name); + assert (hci.cur_name[1]); + no_diffs++; + if (!(dict_info = dict_lookup (hi->dict, hci.cur_name))) + { + isams_p = isams_merge (hi->isams, isams_i); + no_insertions++; + dict_insert (hi->dict, this_name, sizeof(ISAMS_P), &isams_p); + } + else + abort(); + } + xfree (isams_i); + return 0; +} + + int heap_inp (struct heap_info *hi) { char *info; @@ -491,7 +564,7 @@ int heap_inp (struct heap_info *hi) break; memcpy (key_buf + key_buf_ptr, next_key, KEY_SIZE); key_buf_ptr += KEY_SIZE; - if (key_buf_ptr+KEY_SIZE >= key_buf_size) + if (key_buf_ptr+(int) KEY_SIZE >= key_buf_size) { char *new_key_buf; new_key_buf = xmalloc (key_buf_size + INP_BUF_ADD); @@ -503,11 +576,10 @@ int heap_inp (struct heap_info *hi) } no_diffs++; nmemb = key_buf_ptr / KEY_SIZE; - assert (nmemb*KEY_SIZE == key_buf_ptr); + assert (nmemb * (int) KEY_SIZE == key_buf_ptr); if ((info = dict_lookup (hi->dict, cur_name))) { ISAM_P isam_p, isam_p2; - logf (LOG_DEBUG, "updating %s", 1+cur_name); memcpy (&isam_p, info+1, sizeof(ISAM_P)); isam_p2 = is_merge (hi->isam, isam_p, nmemb, key_buf); if (!isam_p2) @@ -526,7 +598,6 @@ int heap_inp (struct heap_info *hi) else { ISAM_P isam_p; - logf (LOG_DEBUG, "inserting %s", 1+cur_name); no_insertions++; isam_p = is_merge (hi->isam, 0, nmemb, key_buf); dict_insert (hi->dict, cur_name, sizeof(ISAM_P), &isam_p); @@ -556,8 +627,8 @@ void progressFunc (struct key_file *keyp, void *info) if (now >= p->lastTime+10) { p->lastTime = now; - remaining = (now - p->startTime)* - ((double) p->totalBytes/p->totalOffset - 1.0); + remaining = (time_t) ((now - p->startTime)* + ((double) p->totalBytes/p->totalOffset - 1.0)); if (remaining <= 130) logf (LOG_LOG, "Merge %2.1f%% completed; %ld seconds remaining", (100.0*p->totalOffset) / p->totalBytes, (long) remaining); @@ -568,12 +639,17 @@ void progressFunc (struct key_file *keyp, void *info) p->totalOffset += keyp->buf_size; } -void key_input (int nkeys, int cache) +#ifndef R_OK +#define R_OK 4 +#endif + +void key_input (BFiles bfs, int nkeys, int cache) { Dict dict; ISAM isam = NULL; ISAMC isamc = NULL; + ISAMS isams = NULL; struct key_file **kf; char rbuf[1024]; int i, r; @@ -594,30 +670,42 @@ void key_input (int nkeys, int cache) if (!nkeys) return ; } - dict = dict_open (FNAME_DICT, cache, 1); + dict = dict_open (bfs, FNAME_DICT, cache, 1, 0); if (!dict) { logf (LOG_FATAL, "dict_open fail"); exit (1); } - if (res_get_match (common_resource, "isam", "c", NULL)) + if (res_get_match (common_resource, "isam", "s", NULL)) { - isamc = isc_open (FNAME_ISAMC, 1, key_isamc_m ()); - if (!isamc) + isams = isams_open (bfs, FNAME_ISAMS, 1, + key_isams_m (common_resource)); + if (!isams) { - logf (LOG_FATAL, "isc_open fail"); + logf (LOG_FATAL, "isams_open fail"); exit (1); } } - else + else if (res_get_match (common_resource, "isam", "i", NULL)) { - isam = is_open (FNAME_ISAM, key_compare, 1, sizeof(struct it_key)); + isam = is_open (bfs, FNAME_ISAM, key_compare, 1, + sizeof(struct it_key), common_resource); if (!isam) { logf (LOG_FATAL, "is_open fail"); exit (1); } } + else + { + isamc = isc_open (bfs, FNAME_ISAMC, 1, + key_isamc_m (common_resource)); + if (!isamc) + { + logf (LOG_FATAL, "isc_open fail"); + exit (1); + } + } kf = xmalloc ((1+nkeys) * sizeof(*kf)); progressInfo.totalBytes = 0; progressInfo.totalOffset = 0; @@ -635,19 +723,24 @@ void key_input (int nkeys, int cache) hi->dict = dict; hi->isam = isam; hi->isamc = isamc; + hi->isams = isams; for (i = 1; i<=nkeys; i++) if ((r = key_file_read (kf[i], rbuf))) key_heap_insert (hi, rbuf, r, kf[i]); if (isamc) heap_inpc (hi); - else - heap_inp (hi); + else if (isams) + heap_inps (hi); + else if (isam) + heap_inp (hi); dict_close (dict); if (isam) is_close (isam); if (isamc) isc_close (isamc); + if (isams) + isams_close (isams); for (i = 1; i<=nkeys; i++) {