X-Git-Url: http://sru.miketaylor.org.uk/?a=blobdiff_plain;ds=inline;f=rset%2Frsbetween.c;h=63901cd45463f695295cb09dbd5dd51bdb687b7b;hb=726c42c6ae793b79a5351d2fce805d220d21321e;hp=517aa7af65b0da931de2b7af1d002283134d5992;hpb=896c0427df9d8eff5de6a1735dcd992e067df844;p=idzebra-moved-to-github.git
diff --git a/rset/rsbetween.c b/rset/rsbetween.c
index 517aa7a..63901cd 100644
--- a/rset/rsbetween.c
+++ b/rset/rsbetween.c
@@ -1,4 +1,4 @@
-/* $Id: rsbetween.c,v 1.7 2002-08-02 19:26:57 adam Exp $
+/* $Id: rsbetween.c,v 1.25 2004-09-09 10:08:06 heikki Exp $
Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002
Index Data Aps
@@ -21,50 +21,55 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
*/
+/* rsbetween is (mostly) used for xml searches. It returns the hits of the
+ * "middle" rset, that are in between the "left" and "right" rsets. For
+ * example "Shakespeare" in between "
" and . The thing is
+ * complicated by the inclusion of attributes (from their own rset). If attrs
+ * specified, they must match the "left" rset (start tag). "Hamlet" between
+ * "" and "". (This assumes that the attributes are
+ * indexed to the same seqno as the tags).
+*/
#include
#include
#include
#include
-#include
#include
+#include
+
+#define RSBETWEEN_DEBUG 0
-static void *r_create_between(RSET ct, const struct rset_control *sel, void *parms);
static RSFD r_open_between (RSET ct, int flag);
static void r_close_between (RSFD rfd);
static void r_delete_between (RSET ct);
static void r_rewind_between (RSFD rfd);
-static int r_count_between (RSET ct);
-static int r_read_between (RSFD rfd, void *buf, int *term_index);
+static int r_forward_between(RSFD rfd, void *buf, const void *untilbuf);
+static int r_read_between (RSFD rfd, void *buf);
static int r_write_between (RSFD rfd, const void *buf);
+static void r_pos_between (RSFD rfd, double *current, double *total);
-static const struct rset_control control_between =
+static const struct rset_control control =
{
"between",
- r_create_between,
+ r_delete_between,
r_open_between,
r_close_between,
- r_delete_between,
r_rewind_between,
- r_count_between,
+ r_forward_between,
+ r_pos_between,
r_read_between,
r_write_between,
};
-const struct rset_control *rset_kind_between = &control_between;
+const struct rset_control *rset_kind_between = &control;
struct rset_between_info {
- int key_size;
- RSET rset_l;
- RSET rset_m;
- RSET rset_r;
- RSET rset_attr;
- int term_index_s;
- int (*cmp)(const void *p1, const void *p2);
- char *(*printer)(const void *p1, char *buf);
- struct rset_between_rfd *rfd_list;
+ RSET rset_l; /* left arg, start tag */
+ RSET rset_m; /* the thing itself */
+ RSET rset_r; /* right arg, end tag */
+ RSET rset_attr; /* attributes , optional */
};
struct rset_between_rfd {
@@ -76,231 +81,203 @@ struct rset_between_rfd {
int more_m;
int more_r;
int more_attr;
- int term_index_l;
- int term_index_m;
- int term_index_r;
void *buf_l;
void *buf_m;
void *buf_r;
void *buf_attr;
- int level;
- struct rset_between_rfd *next;
- struct rset_between_info *info;
+ int level; /* counting start/end tags */
+ zint hits;
};
-static void *r_create_between (RSET ct, const struct rset_control *sel,
- void *parms)
+#if RSBETWEEN_DEBUG
+static void log2 (struct rset_between_rfd *p, char *msg, int cmp_l, int cmp_r)
{
- rset_between_parms *between_parms = (rset_between_parms *) parms;
- struct rset_between_info *info;
-
- info = (struct rset_between_info *) xmalloc (sizeof(*info));
- info->key_size = between_parms->key_size;
- info->rset_l = between_parms->rset_l;
- info->rset_m = between_parms->rset_m;
- info->rset_r = between_parms->rset_r;
- info->rset_attr = between_parms->rset_attr;
- if (rset_is_volatile(info->rset_l) ||
- rset_is_volatile(info->rset_m) ||
- rset_is_volatile(info->rset_r))
- ct->flags |= RSET_FLAG_VOLATILE;
- info->cmp = between_parms->cmp;
- info->printer = between_parms->printer;
- info->rfd_list = NULL;
-
- info->term_index_s = info->rset_l->no_rset_terms;
- if (info->rset_m)
- {
- ct->no_rset_terms =
- info->rset_l->no_rset_terms +
- info->rset_m->no_rset_terms +
- info->rset_r->no_rset_terms;
- ct->rset_terms = (RSET_TERM *)
- xmalloc (sizeof (*ct->rset_terms) * ct->no_rset_terms);
- memcpy (ct->rset_terms, info->rset_l->rset_terms,
- info->rset_l->no_rset_terms * sizeof(*ct->rset_terms));
- memcpy (ct->rset_terms + info->rset_l->no_rset_terms,
- info->rset_m->rset_terms,
- info->rset_m->no_rset_terms * sizeof(*ct->rset_terms));
- memcpy (ct->rset_terms + info->rset_l->no_rset_terms +
- info->rset_m->no_rset_terms,
- info->rset_r->rset_terms,
- info->rset_r->no_rset_terms * sizeof(*ct->rset_terms));
- }
- else
- {
- ct->no_rset_terms =
- info->rset_l->no_rset_terms +
- info->rset_r->no_rset_terms;
- ct->rset_terms = (RSET_TERM *)
- xmalloc (sizeof (*ct->rset_terms) * ct->no_rset_terms);
- memcpy (ct->rset_terms, info->rset_l->rset_terms,
- info->rset_l->no_rset_terms * sizeof(*ct->rset_terms));
- memcpy (ct->rset_terms + info->rset_l->no_rset_terms,
- info->rset_r->rset_terms,
- info->rset_r->no_rset_terms * sizeof(*ct->rset_terms));
- }
+ char buf_l[32];
+ char buf_m[32];
+ char buf_r[32];
+ logf(LOG_DEBUG,"btw: %s l=%s(%d/%d) m=%s(%d) r=%s(%d/%d), lev=%d",
+ msg,
+ (*p->info->printer)(p->buf_l, buf_l), p->more_l, cmp_l,
+ (*p->info->printer)(p->buf_m, buf_m), p->more_m,
+ (*p->info->printer)(p->buf_r, buf_r), p->more_r, cmp_r,
+ p->level);
+}
+#endif
- return info;
+RSET rsbetween_create( NMEM nmem, const struct key_control *kcontrol,
+ int scope,
+ RSET rset_l, RSET rset_m, RSET rset_r, RSET rset_attr)
+{
+ RSET rnew=rset_create_base(&control, nmem, kcontrol, scope);
+ struct rset_between_info *info=
+ (struct rset_between_info *) nmem_malloc(rnew->nmem,sizeof(*info));
+ info->rset_l = rset_l;
+ info->rset_m = rset_m;
+ info->rset_r = rset_r;
+ info->rset_attr = rset_attr;
+ rnew->priv=info;
+ return rnew;
}
+
+static void r_delete_between (RSET ct)
+{
+ struct rset_between_info *info = (struct rset_between_info *) ct->priv;
+
+ rset_delete (info->rset_l);
+ rset_delete (info->rset_m);
+ rset_delete (info->rset_r);
+ if (info->rset_attr)
+ rset_delete (info->rset_attr);
+}
+
+
static RSFD r_open_between (RSET ct, int flag)
{
- struct rset_between_info *info = (struct rset_between_info *) ct->buf;
- struct rset_between_rfd *rfd;
+ struct rset_between_info *info = (struct rset_between_info *) ct->priv;
+ RSFD rfd;
+ struct rset_between_rfd *p;
if (flag & RSETF_WRITE)
{
- logf (LOG_FATAL, "between set type is read-only");
- return NULL;
+ logf (LOG_FATAL, "between set type is read-only");
+ return NULL;
}
- rfd = (struct rset_between_rfd *) xmalloc (sizeof(*rfd));
- rfd->next = info->rfd_list;
- info->rfd_list = rfd;
- rfd->info = info;
-
- rfd->buf_l = xmalloc (info->key_size);
- rfd->buf_m = xmalloc (info->key_size);
- rfd->buf_r = xmalloc (info->key_size);
- rfd->buf_attr = xmalloc (info->key_size);
-
- rfd->rfd_l = rset_open (info->rset_l, RSETF_READ);
- rfd->rfd_m = rset_open (info->rset_m, RSETF_READ);
- rfd->rfd_r = rset_open (info->rset_r, RSETF_READ);
+ rfd=rfd_create_base(ct);
+ if (rfd->priv)
+ p=(struct rset_between_rfd *)rfd->priv;
+ else {
+ p = (struct rset_between_rfd *) nmem_malloc(ct->nmem, (sizeof(*p)));
+ rfd->priv=p;
+ p->buf_l = nmem_malloc(ct->nmem, (ct->keycontrol->key_size));
+ p->buf_m = nmem_malloc(ct->nmem, (ct->keycontrol->key_size));
+ p->buf_r = nmem_malloc(ct->nmem, (ct->keycontrol->key_size));
+ p->buf_attr = nmem_malloc(ct->nmem, (ct->keycontrol->key_size));
+ }
+
+ p->rfd_l = rset_open (info->rset_l, RSETF_READ);
+ p->rfd_m = rset_open (info->rset_m, RSETF_READ);
+ p->rfd_r = rset_open (info->rset_r, RSETF_READ);
- rfd->more_l = rset_read (info->rset_l, rfd->rfd_l, rfd->buf_l,
- &rfd->term_index_l);
- rfd->more_m = rset_read (info->rset_m, rfd->rfd_m, rfd->buf_m,
- &rfd->term_index_m);
- rfd->more_r = rset_read (info->rset_r, rfd->rfd_r, rfd->buf_r,
- &rfd->term_index_r);
+ p->more_l = rset_read (p->rfd_l, p->buf_l);
+ p->more_m = rset_read (p->rfd_m, p->buf_m);
+ p->more_r = rset_read (p->rfd_r, p->buf_r);
if (info->rset_attr)
{
- int dummy;
- rfd->rfd_attr = rset_open (info->rset_attr, RSETF_READ);
- rfd->more_attr = rset_read (info->rset_attr, rfd->rfd_attr,
- rfd->buf_attr, &dummy);
+ p->rfd_attr = rset_open (info->rset_attr, RSETF_READ);
+ p->more_attr = rset_read (p->rfd_attr, p->buf_attr);
}
- rfd->level=0;
+ p->level=0;
+ p->hits=0;
return rfd;
}
static void r_close_between (RSFD rfd)
{
- struct rset_between_info *info = ((struct rset_between_rfd*)rfd)->info;
- struct rset_between_rfd **rfdp;
-
- for (rfdp = &info->rfd_list; *rfdp; rfdp = &(*rfdp)->next)
- if (*rfdp == rfd)
- {
- xfree ((*rfdp)->buf_l);
- xfree ((*rfdp)->buf_m);
- xfree ((*rfdp)->buf_r);
- xfree ((*rfdp)->buf_attr);
- rset_close (info->rset_l, (*rfdp)->rfd_l);
- rset_close (info->rset_m, (*rfdp)->rfd_m);
- rset_close (info->rset_r, (*rfdp)->rfd_r);
- if (info->rset_attr)
- rset_close (info->rset_attr, (*rfdp)->rfd_attr);
-
- *rfdp = (*rfdp)->next;
- xfree (rfd);
- return;
- }
- logf (LOG_FATAL, "r_close_between but no rfd match!");
- assert (0);
-}
+ struct rset_between_info *info =(struct rset_between_info *)rfd->rset->priv;
+ struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
-static void r_delete_between (RSET ct)
-{
- struct rset_between_info *info = (struct rset_between_info *) ct->buf;
-
- assert (info->rfd_list == NULL);
- xfree (ct->rset_terms);
- rset_delete (info->rset_l);
- rset_delete (info->rset_m);
- rset_delete (info->rset_r);
+ rset_close (p->rfd_l);
+ rset_close (p->rfd_m);
+ rset_close (p->rfd_r);
if (info->rset_attr)
- rset_delete (info->rset_attr);
- xfree (info);
+ rset_close (p->rfd_attr);
+ rfd_delete_base(rfd);
}
static void r_rewind_between (RSFD rfd)
{
- struct rset_between_info *info = ((struct rset_between_rfd*)rfd)->info;
- struct rset_between_rfd *p = (struct rset_between_rfd *) rfd;
+ struct rset_between_info *info =(struct rset_between_info *)rfd->rset->priv;
+ struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
+#if RSBETWEEN_DEBUG
logf (LOG_DEBUG, "rsbetween_rewind");
- rset_rewind (info->rset_l, p->rfd_l);
- rset_rewind (info->rset_m, p->rfd_m);
- rset_rewind (info->rset_r, p->rfd_r);
- p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l, &p->term_index_l);
- p->more_m = rset_read (info->rset_m, p->rfd_m, p->buf_m, &p->term_index_m);
- p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r, &p->term_index_r);
+#endif
+ rset_rewind (p->rfd_l);
+ rset_rewind (p->rfd_m);
+ rset_rewind (p->rfd_r);
+ p->more_l = rset_read (p->rfd_l, p->buf_l);
+ p->more_m = rset_read (p->rfd_m, p->buf_m);
+ p->more_r = rset_read (p->rfd_r, p->buf_r);
if (info->rset_attr)
{
- int dummy;
- rset_rewind (info->rset_attr, p->rfd_attr);
- p->more_attr = rset_read (info->rset_attr, p->rfd_attr, p->buf_attr,
- &dummy);
+ rset_rewind (p->rfd_attr);
+ p->more_attr = rset_read (p->rfd_attr, p->buf_attr);
}
p->level=0;
+ p->hits=0;
}
-static int r_count_between (RSET ct)
-{
- return 0;
-}
-static void logit( struct rset_between_info *info, char *prefix, void *l, void *m, void *r)
+
+static int r_forward_between(RSFD rfd, void *buf, const void *untilbuf)
{
- char buf_l[32];
- char buf_m[32];
- char buf_r[32];
- logf(LOG_DEBUG,"btw: %s l=%s m=%s r=%s",
- prefix,
- (*info->printer)(l, buf_l),
- (*info->printer)(m, buf_m),
- (*info->printer)(r, buf_r) );
+ struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
+ int rc;
+#if RSBETWEEN_DEBUG
+ log2( p, "fwd: before forward", 0,0);
+#endif
+ /* It is enough to forward the m pointer here, the read will */
+ /* naturally forward the l, m, and attr pointers */
+ if (p->more_m)
+ p->more_m=rset_forward(p->rfd_m, p->buf_m,untilbuf);
+#if RSBETWEEN_DEBUG
+ log2( p, "fwd: after forward M", 0,0);
+#endif
+ rc = r_read_between(rfd, buf);
+#if RSBETWEEN_DEBUG
+ log2( p, "fwd: after forward", 0,0);
+#endif
+ return rc;
}
-static int r_read_between (RSFD rfd, void *buf, int *term_index)
+
+
+
+static int r_read_between (RSFD rfd, void *buf)
{
- struct rset_between_rfd *p = (struct rset_between_rfd *) rfd;
- struct rset_between_info *info = p->info;
- int cmp_l;
- int cmp_r;
- int attr_match;
+ struct rset_between_info *info =(struct rset_between_info *)rfd->rset->priv;
+ struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
+ const struct key_control *kctrl=rfd->rset->keycontrol;
+ int cmp_l=0;
+ int cmp_r=0;
+ int attr_match = 0;
while (p->more_m)
{
- logit( info, "start of loop", p->buf_l, p->buf_m, p->buf_r);
-
- /* forward L until past m, count levels, note rec boundaries */
- if (p->more_l)
- cmp_l= (*info->cmp)(p->buf_l, p->buf_m);
- else
- cmp_l=2; /* past this record */
- logf(LOG_DEBUG, "cmp_l=%d", cmp_l);
+#if RSBETWEEN_DEBUG
+ log2( p, "start of loop", cmp_l, cmp_r);
+#endif
+
+ /* forward L until past m, count levels, note rec boundaries */
+ if (p->more_l)
+ cmp_l= (*kctrl->cmp)(p->buf_l, p->buf_m);
+ else
+ {
+ p->level = 0;
+ cmp_l=rfd->rset->scope; /* past this record */
+ }
+#if RSBETWEEN_DEBUG
+ log2( p, "after first L", cmp_l, cmp_r);
+#endif
while (cmp_l < 0) /* l before m */
- {
- if (cmp_l == -2)
- p->level=0; /* earlier record */
- if (cmp_l == -1)
+ {
+ if (cmp_l <= - rfd->rset->scope) /* ==-2 */
+ p->level=0; /* earlier record */
+ if (cmp_l > - rfd->rset->scope) /* == -1 */
{
- p->level++; /* relevant start tag */
+ p->level++; /* relevant start tag */
if (!info->rset_attr)
attr_match = 1;
else
{
int cmp_attr;
- int dummy_term;
attr_match = 0;
while (p->more_attr)
{
- cmp_attr = (*info->cmp)(p->buf_attr, p->buf_l);
+ cmp_attr = (*kctrl->cmp)(p->buf_attr, p->buf_l);
if (cmp_attr == 0)
{
attr_match = 1;
@@ -308,68 +285,142 @@ static int r_read_between (RSFD rfd, void *buf, int *term_index)
}
else if (cmp_attr > 0)
break;
- p->more_attr = rset_read (info->rset_attr, p->rfd_attr,
- p->buf_attr, &dummy_term);
- }
+ else if (cmp_attr > - rfd->rset->scope) /* == -1 */
+ p->more_attr = rset_read (p->rfd_attr, p->buf_attr);
+ /* if we had a forward that went all the way to
+ * the seqno, we could use that. But fwd only goes
+ * to the sysno */
+ else if (cmp_attr <= - rfd->rset->scope) /* ==-2 */
+ {
+ p->more_attr = rset_forward( p->rfd_attr,
+ p->buf_attr, p->buf_l);
+#if RSBETWEEN_DEBUG
+ logf(LOG_DEBUG, "btw: after frowarding attr m=%d",
+ p->more_attr);
+#endif
+ }
+ } /* while more_attr */
}
}
+#define NEWCODE 1
+#if NEWCODE
+ if (cmp_l <= - rfd->rset->scope )/* ==-2 */
+ {
+ if (p->more_l)
+ {
+ p->more_l=rset_forward(p->rfd_l, p->buf_l, p->buf_m);
+ if (p->more_l)
+ cmp_l= (*kctrl->cmp)(p->buf_l, p->buf_m);
+ else
+ cmp_l=rfd->rset->scope; /*2*/
+#if RSBETWEEN_DEBUG
+ log2( p, "after forwarding L", cmp_l, cmp_r);
+#endif
+ }
+ } else
+ {
+ p->more_l = rset_read (p->rfd_l, p->buf_l);
+ }
+#else
+ p->more_l = rset_read (p->rfd_l, p->buf_l);
+#endif
if (p->more_l)
{
- p->more_l = rset_read (info->rset_l, p->rfd_l, p->buf_l,
- &p->term_index_l);
- cmp_l= (*info->cmp)(p->buf_l, p->buf_m);
- logit( info, "forwarded L", p->buf_l, p->buf_m, p->buf_r);
- logf(LOG_DEBUG, " cmp_l=%d", cmp_l);
+ cmp_l= (*kctrl->cmp)(p->buf_l, p->buf_m);
}
else
- cmp_l=2;
+ cmp_l=rfd->rset->scope; /*2*/
+#if RSBETWEEN_DEBUG
+ log2( p, "end of L loop", cmp_l, cmp_r);
+#endif
} /* forward L */
- /* forward R until past m, count levels */
+ /* forward R until past m, count levels */
+#if RSBETWEEN_DEBUG
+ log2( p, "Before moving R", cmp_l, cmp_r);
+#endif
if (p->more_r)
- cmp_r= (*info->cmp)(p->buf_r, p->buf_m);
- else
- cmp_r=2;
- logf(LOG_DEBUG, "cmp_r=%d", cmp_r);
+ cmp_r= (*kctrl->cmp)(p->buf_r, p->buf_m);
+ else
+ cmp_r=rfd->rset->scope; /*2*/
+#if RSBETWEEN_DEBUG
+ log2( p, "after first R", cmp_l, cmp_r);
+#endif
while (cmp_r < 0) /* r before m */
- {
- /* -2, earlier record, doesn't matter */
- if (cmp_r == -1)
- p->level--; /* relevant end tag */
+ {
+ /* -2, earlier record, don't count level */
+ if (cmp_r > -rfd->rset->scope) /* == -1 */
+ p->level--; /* relevant end tag */
if (p->more_r)
{
- p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r,
- &p->term_index_r);
- cmp_r= (*info->cmp)(p->buf_r, p->buf_m);
- logit( info, "forwarded R", p->buf_l, p->buf_m, p->buf_r);
- logf(LOG_DEBUG, " cmp_r=%d", cmp_r);
+#if NEWCODE
+ if (cmp_r <= - rfd->rset->scope) /* == -2 */
+ {
+ p->more_r=rset_forward(p->rfd_r, p->buf_r, p->buf_m);
+ } else
+ {
+ p->more_r = rset_read (p->rfd_r, p->buf_r);
+ }
+ if (p->more_r)
+ cmp_r= (*kctrl->cmp)(p->buf_r, p->buf_m);
+
+#else
+ p->more_r = rset_read (p->rfd_r, p->buf_r);
+ cmp_r= (*kctrl->cmp)(p->buf_r, p->buf_m);
+#endif
}
else
- cmp_r=2;
+ cmp_r=rfd->rset->scope; /*2*/
+#if RSBETWEEN_DEBUG
+ log2( p, "End of R loop", cmp_l, cmp_r);
+#endif
} /* forward R */
-
- if ( ( p->level <= 0 ) && ! p->more_l)
- return 0; /* no more start tags, nothing more to find */
- if ( attr_match && p->level > 0) /* within a tag pair (or deeper) */
- {
- memcpy (buf, p->buf_m, info->key_size);
- *term_index = p->term_index_m;
- logit( info, "Returning a hit (m)", p->buf_l, p->buf_m, p->buf_r);
- p->more_m = rset_read (info->rset_m, p->rfd_m, p->buf_m,
- &p->term_index_m);
- return 1;
- }
- else
- if ( ! p->more_l ) /* not in data, no more starts */
- return 0; /* ergo, nothing can be found. stop scanning */
+ if ( ( p->level <= 0 ) && ! p->more_l)
+ return 0; /* no more start tags, nothing more to find */
- p->more_m = rset_read (info->rset_m, p->rfd_m, p->buf_m,
- &p->term_index_m);
+ if ( attr_match && p->level > 0) /* within a tag pair (or deeper) */
+ {
+ memcpy (buf, p->buf_m, kctrl->key_size);
+#if RSBETWEEN_DEBUG
+ log2( p, "Returning a hit (and forwarding m)", cmp_l, cmp_r);
+#endif
+ p->more_m = rset_read (p->rfd_m, p->buf_m);
+ if (cmp_l >= rfd->rset->scope) /* == 2 */
+ p->level = 0;
+ p->hits++;
+ return 1;
+ }
+ else if ( ! p->more_l ) /* not in data, no more starts */
+ {
+#if RSBETWEEN_DEBUG
+ log2( p, "no more starts, exiting without a hit", cmp_l, cmp_r);
+#endif
+ return 0; /* ergo, nothing can be found. stop scanning */
+ }
+#if NEWCODE
+ if (cmp_l >= rfd->rset->scope) /* == 2 */
+ {
+ p->level = 0;
+ p->more_m=rset_forward(p->rfd_m, p->buf_m, p->buf_l);
+ } else
+ {
+ p->more_m = rset_read (p->rfd_m, p->buf_m);
+ }
+#else
+ if (cmp_l >= rfd->rset->scope ) /* == 2 */
+ p->level = 0;
+ p->more_m = rset_read (p->rfd_m, p->buf_m);
+#endif
+#if RSBETWEEN_DEBUG
+ log2( p, "End of M loop", cmp_l, cmp_r);
+#endif
} /* while more_m */
-
- logf(LOG_DEBUG,"Exiting, no more stuff in m");
+
+#if RSBETWEEN_DEBUG
+ log2( p, "Exiting, nothing more in m", cmp_l, cmp_r);
+#endif
return 0; /* no more data possible */
@@ -382,3 +433,36 @@ static int r_write_between (RSFD rfd, const void *buf)
return -1;
}
+
+static void r_pos_between (RSFD rfd, double *current, double *total)
+{
+ struct rset_between_rfd *p=(struct rset_between_rfd *)rfd->priv;
+ double lcur,ltot;
+ double mcur,mtot;
+ double rcur,rtot;
+ double r;
+ ltot=-1; rtot=-1;
+ rset_pos(p->rfd_l, &lcur, <ot);
+ rset_pos(p->rfd_m, &mcur, &mtot);
+ rset_pos(p->rfd_r, &rcur, &rtot);
+ if ( (ltot<0) && (mtot<0) && (rtot<0) ) { /*no position */
+ *current=mcur; /* return same as you got */
+ *total=mtot; /* probably -1 for not available */
+ }
+ if ( ltot<0) { ltot=0; lcur=0;} /* if only one useful, use it */
+ if ( mtot<0) { mtot=0; mcur=0;}
+ if ( rtot<0) { rtot=0; rcur=0;}
+ if ( ltot+mtot+rtot < 1 ) { /* empty rset */
+ *current=0;
+ *total=0;
+ return;
+ }
+ r=1.0*(lcur+mcur+rcur)/(ltot+mtot+rtot); /* weighed average of l and r */
+ *current=p->hits;
+ *total=*current/r ;
+#if RSBETWEEN_DEBUG
+ yaz_log(LOG_DEBUG,"betw_pos: (%s/%s) %0.1f/%0.1f= %0.4f ",
+ info->rset_l->control->desc, info->rset_r->control->desc,
+ *current, *total, r);
+#endif
+}