X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=rset%2Frsm_or.c;h=5232aa061d69b3528a436d416cc5c1a4ca170749;hb=2b1851bd5565e3d21f9cf9a37661a584c063b75f;hp=72f09fa886b63b74f650a7bdcdfb024ad7235967;hpb=33b386a95c0aac273527d596ce1aafa0dc567b7b;p=idzebra-moved-to-github.git diff --git a/rset/rsm_or.c b/rset/rsm_or.c index 72f09fa..5232aa0 100644 --- a/rset/rsm_or.c +++ b/rset/rsm_or.c @@ -1,40 +1,23 @@ /* - * Copyright (C) 1994-1998, Index Data I/S + * Copyright (C) 1994-2002, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * - * $Log: rsm_or.c,v $ - * Revision 1.6 1998-03-05 08:36:28 adam - * New result set model. - * - * Revision 1.5 1997/12/18 10:54:25 adam - * New method result set method rs_hits that returns the number of - * hits in result-set (if known). The ranked result set returns real - * number of hits but only when not combined with other operands. - * - * Revision 1.4 1997/10/31 12:37:55 adam - * Code calls xfree() instead of free(). - * - * Revision 1.3 1997/09/09 13:38:16 adam - * Partial port to WIN95/NT. - * - * Revision 1.2 1996/12/23 15:30:49 adam - * Work on truncation. - * - * Revision 1.1 1996/12/20 11:07:21 adam - * Implemented Multi-or result set. + * $Id: rsm_or.c,v 1.11 2002-03-20 20:24:30 adam Exp $ * */ + #include #include #include #include +#include +#if ZMBOL #include #include #include -#include static void *r_create(RSET ct, const struct rset_control *sel, void *parms); static RSFD r_open (RSET ct, int flag); @@ -92,6 +75,8 @@ struct rset_mor_rfd { struct rset_mor_rfd *next; struct rset_mor_info *info; struct trunc_info *ti; + int *countp; + char *pbuf; }; static void heap_swap (struct trunc_info *ti, int i1, int i2) @@ -146,19 +131,19 @@ static struct trunc_info *heap_init (int size, int key_size, int (*cmp)(const void *p1, const void *p2)) { - struct trunc_info *ti = xmalloc (sizeof(*ti)); + struct trunc_info *ti = (struct trunc_info *) xmalloc (sizeof(*ti)); int i; ++size; ti->heapnum = 0; ti->keysize = key_size; ti->cmp = cmp; - ti->indx = xmalloc (size * sizeof(*ti->indx)); - ti->heap = xmalloc (size * sizeof(*ti->heap)); - ti->ptr = xmalloc (size * sizeof(*ti->ptr)); - ti->swapbuf = xmalloc (ti->keysize); - ti->tmpbuf = xmalloc (ti->keysize); - ti->buf = xmalloc (size * ti->keysize); + ti->indx = (int *) xmalloc (size * sizeof(*ti->indx)); + ti->heap = (char **) xmalloc (size * sizeof(*ti->heap)); + ti->ptr = (int *) xmalloc (size * sizeof(*ti->ptr)); + ti->swapbuf = (char *) xmalloc (ti->keysize); + ti->tmpbuf = (char *) xmalloc (ti->keysize); + ti->buf = (char *) xmalloc (size * ti->keysize); for (i = size; --i >= 0; ) { ti->ptr[i] = i; @@ -169,6 +154,7 @@ struct trunc_info *heap_init (int size, int key_size, static void heap_close (struct trunc_info *ti) { + xfree (ti->buf); xfree (ti->ptr); xfree (ti->indx); xfree (ti->heap); @@ -179,11 +165,11 @@ static void heap_close (struct trunc_info *ti) static void *r_create (RSET ct, const struct rset_control *sel, void *parms) { - rset_m_or_parms *r_parms = parms; + rset_m_or_parms *r_parms = (rset_m_or_parms *) parms; struct rset_mor_info *info; ct->flags |= RSET_FLAG_VOLATILE; - info = xmalloc (sizeof(*info)); + info = (struct rset_mor_info *) xmalloc (sizeof(*info)); info->key_size = r_parms->key_size; assert (info->key_size > 1); info->cmp = r_parms->cmp; @@ -192,22 +178,22 @@ static void *r_create (RSET ct, const struct rset_control *sel, void *parms) info->isc = r_parms->isc; info->no_isam_positions = r_parms->no_isam_positions; - info->isam_positions = xmalloc (sizeof(*info->isam_positions) * - info->no_isam_positions); + info->isam_positions = (ISAM_P *) + xmalloc (sizeof(*info->isam_positions) * info->no_isam_positions); memcpy (info->isam_positions, r_parms->isam_positions, sizeof(*info->isam_positions) * info->no_isam_positions); info->rfd_list = NULL; ct->no_rset_terms = 1; - ct->rset_terms = xmalloc (sizeof(*ct->rset_terms)); - ct->rset_terms[0] = rset_term_dup (r_parms->rset_term); + ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms)); + ct->rset_terms[0] = r_parms->rset_term; return info; } static RSFD r_open (RSET ct, int flag) { struct rset_mor_rfd *rfd; - struct rset_mor_info *info = ct->buf; + struct rset_mor_info *info = (struct rset_mor_info *) ct->buf; int i; if (flag & RSETF_WRITE) @@ -215,13 +201,14 @@ static RSFD r_open (RSET ct, int flag) logf (LOG_FATAL, "m_or set type is read-only"); return NULL; } - rfd = xmalloc (sizeof(*rfd)); + rfd = (struct rset_mor_rfd *) xmalloc (sizeof(*rfd)); rfd->flag = flag; rfd->next = info->rfd_list; rfd->info = info; info->rfd_list = rfd; - rfd->ispt = xmalloc (sizeof(*rfd->ispt) * info->no_isam_positions); + rfd->ispt = (ISAMC_PP *) + xmalloc (sizeof(*rfd->ispt) * info->no_isam_positions); rfd->ti = heap_init (info->no_isam_positions, info->key_size, info->cmp); @@ -241,6 +228,13 @@ static RSFD r_open (RSET ct, int flag) } } rfd->position = info->no_save_positions; + + if (ct->no_rset_terms == 1) + rfd->countp = &ct->rset_terms[0]->count; + else + rfd->countp = 0; + rfd->pbuf = xmalloc (info->key_size); + r_rewind (rfd); return rfd; } @@ -261,6 +255,7 @@ static void r_close (RSFD rfd) if (((struct rset_mor_rfd *) rfd)->ispt[i]) isc_pp_close (((struct rset_mor_rfd *) rfd)->ispt[i]); xfree (((struct rset_mor_rfd *)rfd)->ispt); + xfree (((struct rset_mor_rfd *)rfd)->pbuf); xfree (rfd); return; } @@ -270,7 +265,7 @@ static void r_close (RSFD rfd) static void r_delete (RSET ct) { - struct rset_mor_info *info = ct->buf; + struct rset_mor_info *info = (struct rset_mor_info *) ct->buf; int i; assert (info->rfd_list == NULL); @@ -294,7 +289,8 @@ static int r_count (RSET ct) static int r_read (RSFD rfd, void *buf, int *term_index) { - struct trunc_info *ti = ((struct rset_mor_rfd *) rfd)->ti; + struct rset_mor_rfd *mrfd = (struct rset_mor_rfd *) rfd; + struct trunc_info *ti = mrfd->ti; int n = ti->indx[ti->ptr[1]]; if (!ti->heapnum) @@ -312,6 +308,12 @@ static int r_read (RSFD rfd, void *buf, int *term_index) } else heap_delete (ti); + if (mrfd->countp && ( + *mrfd->countp == 0 || (*ti->cmp)(buf, mrfd->pbuf) > 1)) + { + memcpy (mrfd->pbuf, buf, ti->keysize); + (*mrfd->countp)++; + } return 1; } while (1) @@ -328,6 +330,12 @@ static int r_read (RSFD rfd, void *buf, int *term_index) break; } } + if (mrfd->countp && ( + *mrfd->countp == 0 || (*ti->cmp)(buf, mrfd->pbuf) > 1)) + { + memcpy (mrfd->pbuf, buf, ti->keysize); + (*mrfd->countp)++; + } return 1; } @@ -336,3 +344,4 @@ static int r_write (RSFD rfd, const void *buf) logf (LOG_FATAL, "mor set type is read-only"); return -1; } +#endif