From c04a10ad2c24474c9c86a8a1453f6f40e4bc1853 Mon Sep 17 00:00:00 2001 From: Heikki Levanto Date: Wed, 29 Sep 2004 11:00:56 +0000 Subject: [PATCH] Fixed the rsmultior forward problem. Re-enabled using rsmultior in rstrunc (it created a multior, but didn't use it. Doh!) --- index/trunc.c | 3 ++- rset/rsmultiandor.c | 45 ++++++++++++++++++++++++++++----------------- 2 files changed, 30 insertions(+), 18 deletions(-) diff --git a/index/trunc.c b/index/trunc.c index 4ada4dc..a683a0c 100644 --- a/index/trunc.c +++ b/index/trunc.c @@ -1,4 +1,4 @@ -/* $Id: trunc.c,v 1.44 2004-09-09 10:08:05 heikki Exp $ +/* $Id: trunc.c,v 1.45 2004-09-29 11:00:56 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 Index Data Aps @@ -439,6 +439,7 @@ RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no, zi->reg->isamb, isam_p[i] ); r=rsmultior_create( rset_nmem, kctrl, scope, no, rsets); xfree(rsets); + return r; } qsort (isam_p, no, sizeof(*isam_p), isamc_trunc_cmp); } diff --git a/rset/rsmultiandor.c b/rset/rsmultiandor.c index 7b6b69a..e98c4a7 100644 --- a/rset/rsmultiandor.c +++ b/rset/rsmultiandor.c @@ -1,4 +1,4 @@ -/* $Id: rsmultiandor.c,v 1.3 2004-09-28 16:39:46 heikki Exp $ +/* $Id: rsmultiandor.c,v 1.4 2004-09-29 11:00:57 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -306,7 +306,7 @@ static RSFD r_open_andor (RSET ct, int flag, int is_and) if (flag & RSETF_WRITE) { - logf (LOG_FATAL, "multior set type is read-only"); + logf (LOG_FATAL, "multiandor set type is read-only"); return NULL; } rfd=rfd_create_base(ct); @@ -386,23 +386,39 @@ static void r_close (RSFD rfd) static int r_forward_or(RSFD rfd, void *buf, const void *untilbuf) +{ /* while heap head behind untilbuf, forward it and rebalance heap */ + struct rset_multiandor_rfd *p=rfd->priv; + const struct key_control *kctrl=rfd->rset->keycontrol; + if (heap_empty(p->h)) + return 0; + while ( (*kctrl->cmp)(p->h->heap[1]->buf,untilbuf) < -rfd->rset->scope ) + { + if ( rset_forward(p->h->heap[1]->fd, p->h->heap[1]->buf, untilbuf) ) + heap_balance(p->h); + else + { + heap_delete(p->h); + if (heap_empty(p->h)) + return 0; + } + + } + return r_read_or(rfd,buf); +} + + +static int r_read_or (RSFD rfd, void *buf) { struct rset_multiandor_rfd *mrfd=rfd->priv; const struct key_control *kctrl=rfd->rset->keycontrol; - struct heap_item it; + struct heap_item *it; int rdres; if (heap_empty(mrfd->h)) return 0; - it = *(mrfd->h->heap[1]); - memcpy(buf,it.buf, kctrl->key_size); - /* FIXME - This is not right ! */ - /* If called with an untilbuf, we need to compare to that, and */ - /* forward until we are somewhere! */ + it = mrfd->h->heap[1]; + memcpy(buf,it->buf, kctrl->key_size); (mrfd->hits)++; - if (untilbuf) - rdres=rset_forward(it.fd, it.buf, untilbuf); - else - rdres=rset_read(it.fd, it.buf); + rdres=rset_read(it->fd, it->buf); if ( rdres ) heap_balance(mrfd->h); else @@ -411,11 +427,6 @@ static int r_forward_or(RSFD rfd, void *buf, const void *untilbuf) } -static int r_read_or (RSFD rfd, void *buf) -{ - return r_forward_or(rfd, buf,0); -} - static int r_read_and (RSFD rfd, void *buf) { /* Has to return all hits where each item points to the */ /* same sysno (scope), in order. Keep an extra key (hitkey) */ -- 1.7.10.4