X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=rset%2Frsmultiandor.c;h=af87249395e9da6a40db05512093702bfa4e990e;hb=6ec32a146d639c16e9929435fdbfd8d915e918b3;hp=7b6b69a55257e5f54df9d18847ab60ad7ac2c0a1;hpb=6f514a5c6e5430d6bd9cc036e0faaa4477d04410;p=idzebra-moved-to-github.git diff --git a/rset/rsmultiandor.c b/rset/rsmultiandor.c index 7b6b69a..af87249 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.5 2004-09-30 09:53:05 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002 Index Data Aps @@ -47,7 +47,6 @@ static RSFD r_open_and (RSET ct, int flag); static RSFD r_open_or (RSET ct, int flag); static void r_close (RSFD rfd); static void r_delete (RSET ct); -static void r_rewind (RSFD rfd); static int r_read_and (RSFD rfd, void *buf); static int r_read_or (RSFD rfd, void *buf); static int r_write (RSFD rfd, const void *buf); @@ -63,7 +62,6 @@ static const struct rset_control control_or = r_delete, r_open_or, r_close, - r_rewind, r_forward_or, r_pos, r_read_or, @@ -75,7 +73,6 @@ static const struct rset_control control_and = r_delete, r_open_and, r_close, - r_rewind, r_forward_and, r_pos, r_read_and, @@ -306,7 +303,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 +383,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 +424,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) */ @@ -556,11 +564,6 @@ static void r_pos (RSFD rfd, double *current, double *total) } -static void r_rewind (RSFD rfd) -{ - assert(!"rewind not implemented yet"); - /* FIXME - rewind all parts, rebalance heap, clear hits */ -} static int r_write (RSFD rfd, const void *buf) {