Bug fixes in relevance.
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rsbool.c,v $
- * Revision 1.7 1995-10-10 14:00:03 adam
+ * Revision 1.8 1995-10-12 12:41:55 adam
+ * Private info (buf) moved from struct rset_control to struct rset.
+ * Bug fixes in relevance.
+ *
+ * Revision 1.7 1995/10/10 14:00:03 adam
* Function rset_open changed its wflag parameter to general flags.
*
* Revision 1.6 1995/10/06 14:38:05 adam
#include <rsbool.h>
#include <alexutil.h>
-static rset_control *r_create(const struct rset_control *sel, void *parms);
-static RSFD r_open (rset_control *ct, int flag);
+static void *r_create(const struct rset_control *sel, void *parms);
+static RSFD r_open (RSET ct, int flag);
static void r_close (RSFD rfd);
-static void r_delete (rset_control *ct);
+static void r_delete (RSET ct);
static void r_rewind (RSFD rfd);
-static int r_count (rset_control *ct);
+static int r_count (RSET ct);
static int r_read_and (RSFD rfd, void *buf);
static int r_read_or (RSFD rfd, void *buf);
static int r_read_not (RSFD rfd, void *buf);
static const rset_control control_and =
{
"AND set type",
- 0,
r_create,
r_open,
r_close,
static const rset_control control_or =
{
"OR set type",
- 0,
r_create,
r_open,
r_close,
static const rset_control control_not =
{
"NOT set type",
- 0,
r_create,
r_open,
r_close,
struct rset_bool_info *info;
};
-static rset_control *r_create (const struct rset_control *sel, void *parms)
+static void *r_create (const struct rset_control *sel, void *parms)
{
- rset_control *newct;
rset_bool_parms *bool_parms = parms;
struct rset_bool_info *info;
- newct = xmalloc(sizeof(*newct));
- memcpy (newct, sel, sizeof(*sel));
- newct->buf = xmalloc (sizeof(struct rset_bool_info));
- info = (struct rset_bool_info*) newct->buf;
+ info = xmalloc (sizeof(struct rset_bool_info));
info->key_size = bool_parms->key_size;
info->rset_l = bool_parms->rset_l;
info->rset_r = bool_parms->rset_r;
info->cmp = bool_parms->cmp;
info->rfd_list = NULL;
- return newct;
+ return info;
}
-static RSFD r_open (rset_control *ct, int flag)
+static RSFD r_open (RSET ct, int flag)
{
struct rset_bool_info *info = ct->buf;
struct rset_bool_rfd *rfd;
logf (LOG_FATAL, "bool set type is read-only");
return NULL;
}
+ flag = 0;
rfd = xmalloc (sizeof(*rfd));
rfd->next = info->rfd_list;
info->rfd_list = rfd;
assert (0);
}
-static void r_delete (rset_control *ct)
+static void r_delete (RSET ct)
{
struct rset_bool_info *info = ct->buf;
assert (info->rfd_list == NULL);
xfree (info);
- xfree (ct);
}
static void r_rewind (RSFD rfd)
p->more_r = rset_read (info->rset_r, p->rfd_r, p->buf_r);
}
-static int r_count (rset_control *ct)
+static int r_count (RSET ct)
{
return 0;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rset.c,v $
- * Revision 1.6 1995-09-08 14:52:41 adam
+ * Revision 1.7 1995-10-12 12:41:56 adam
+ * Private info (buf) moved from struct rset_control to struct rset.
+ * Bug fixes in relevance.
+ *
+ * Revision 1.6 1995/09/08 14:52:41 adam
* Work on relevance feedback.
*
* Revision 1.5 1995/09/07 13:58:43 adam
RSET new;
logf (LOG_DEBUG, "rs_create(%s)", sel->desc);
- new = xmalloc(sizeof(*new)); /* make dynamic alloc scheme */
- if (!(new->control = (*sel->f_create)(sel, parms)))
- return 0;
+ new = xmalloc(sizeof(*new));
+ new->control = sel;
+ new->buf = (*sel->f_create)(sel, parms);
return new;
}
void rset_delete (RSET rs)
{
- (*rs->control->f_delete)(rs->control);
+ (*rs->control->f_delete)(rs);
xfree(rs);
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rsisam.c,v $
- * Revision 1.12 1995-10-10 14:00:04 adam
+ * Revision 1.13 1995-10-12 12:41:56 adam
+ * Private info (buf) moved from struct rset_control to struct rset.
+ * Bug fixes in relevance.
+ *
+ * Revision 1.12 1995/10/10 14:00:04 adam
* Function rset_open changed its wflag parameter to general flags.
*
* Revision 1.11 1995/10/06 14:38:05 adam
#include <rsisam.h>
#include <alexutil.h>
-static rset_control *r_create(const struct rset_control *sel, void *parms);
-static RSFD r_open (rset_control *ct, int flag);
+static void *r_create(const struct rset_control *sel, void *parms);
+static RSFD r_open (RSET ct, int flag);
static void r_close (RSFD rfd);
-static void r_delete (rset_control *ct);
+static void r_delete (RSET ct);
static void r_rewind (RSFD rfd);
-static int r_count (rset_control *ct);
+static int r_count (RSET ct);
static int r_read (RSFD rfd, void *buf);
static int r_write (RSFD rfd, const void *buf);
static int r_score (RSFD rfd, int *score);
static const rset_control control =
{
"ISAM set type",
- 0,
r_create,
r_open,
r_close,
struct rset_ispt_info *ispt_list;
};
-static rset_control *r_create(const struct rset_control *sel, void *parms)
+static void *r_create(const struct rset_control *sel, void *parms)
{
- rset_control *newct;
rset_isam_parms *pt = parms;
struct rset_isam_info *info;
- newct = xmalloc(sizeof(*newct));
- memcpy(newct, sel, sizeof(*sel));
-
- if (!(newct->buf = xmalloc (sizeof(struct rset_isam_info))))
- return 0;
- info = newct->buf;
+ info = xmalloc (sizeof(struct rset_isam_info));
info->is = pt->is;
info->pos = pt->pos;
info->ispt_list = NULL;
- return newct;
+ return info;
}
-RSFD r_open (rset_control *ct, int flag)
+RSFD r_open (RSET ct, int flag)
{
struct rset_isam_info *info = ct->buf;
struct rset_ispt_info *ptinfo;
assert (0);
}
-static void r_delete (rset_control *ct)
+static void r_delete (RSET ct)
{
struct rset_isam_info *info = ct->buf;
logf (LOG_DEBUG, "rsisam_delete");
assert (info->ispt_list == NULL);
xfree (info);
- xfree (ct);
}
static void r_rewind (RSFD rfd)
is_rewind( ((struct rset_ispt_info*) rfd)->pt);
}
-static int r_count (rset_control *ct)
+static int r_count (RSET ct)
{
return 0;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rsnull.c,v $
- * Revision 1.5 1995-10-10 14:00:04 adam
+ * Revision 1.6 1995-10-12 12:41:57 adam
+ * Private info (buf) moved from struct rset_control to struct rset.
+ * Bug fixes in relevance.
+ *
+ * Revision 1.5 1995/10/10 14:00:04 adam
* Function rset_open changed its wflag parameter to general flags.
*
* Revision 1.4 1995/10/06 14:38:06 adam
#include <rsnull.h>
#include <alexutil.h>
-static rset_control *r_create(const struct rset_control *sel, void *parms);
-static RSFD r_open (rset_control *ct, int flag);
+static void *r_create(const struct rset_control *sel, void *parms);
+static RSFD r_open (RSET ct, int flag);
static void r_close (RSFD rfd);
-static void r_delete (rset_control *ct);
+static void r_delete (RSET ct);
static void r_rewind (RSFD rfd);
-static int r_count (rset_control *ct);
+static int r_count (RSET ct);
static int r_read (RSFD rfd, void *buf);
static int r_write (RSFD rfd, const void *buf);
static int r_score (RSFD rfd, int *score);
static const rset_control control =
{
"NULL set type",
- 0,
r_create,
r_open,
r_close,
const rset_control *rset_kind_null = &control;
-static rset_control *r_create(const struct rset_control *sel, void *parms)
+static void *r_create(const struct rset_control *sel, void *parms)
{
- rset_control *newct;
-
- newct = xmalloc(sizeof(*newct));
- memcpy(newct, sel, sizeof(*sel));
- return newct;
+ return NULL;
}
-static RSFD r_open (rset_control *ct, int flag)
+static RSFD r_open (RSET ct, int flag)
{
if (flag & RSETF_WRITE)
{
{
}
-static void r_delete (rset_control *ct)
+static void r_delete (RSET ct)
{
- xfree(ct);
}
static void r_rewind (RSFD rfd)
logf (LOG_DEBUG, "rsnull_rewind");
}
-static int r_count (rset_control *ct)
+static int r_count (RSET ct)
{
return 0;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rsrel.c,v $
- * Revision 1.6 1995-10-10 14:00:04 adam
+ * Revision 1.7 1995-10-12 12:41:57 adam
+ * Private info (buf) moved from struct rset_control to struct rset.
+ * Bug fixes in relevance.
+ *
+ * Revision 1.6 1995/10/10 14:00:04 adam
* Function rset_open changed its wflag parameter to general flags.
*
* Revision 1.5 1995/10/06 14:38:06 adam
#include <rsrel.h>
#include <alexutil.h>
-static rset_control *r_create(const struct rset_control *sel, void *parms);
-static RSFD r_open (rset_control *ct, int flag);
+static void *r_create(const struct rset_control *sel, void *parms);
+static RSFD r_open (RSET ct, int flag);
static void r_close (RSFD rfd);
-static void r_delete (rset_control *ct);
+static void r_delete (RSET ct);
static void r_rewind (RSFD rfd);
-static int r_count (rset_control *ct);
+static int r_count (RSET ct);
static int r_read (RSFD rfd, void *buf);
static int r_write (RSFD rfd, const void *buf);
static int r_score (RSFD rfd, int *score);
static const rset_control control =
{
"relevance set type",
- 0,
r_create,
r_open,
r_close,
char *key_buf; /* key buffer */
float *score_buf; /* score buffer */
int *sort_idx; /* score sorted index */
- int *sysno_idx; /* sysno sorted index (ring buffer) */
- int sysno_idx_p; /* last sysno sort index */
+ int *sysno_idx; /* sysno sorted index (ring buffer) */
struct rset_rel_rfd *rfd_list;
};
struct rset_rel_rfd {
+ int last_read_pos;
int position;
int flag;
struct rset_rel_rfd *next;
{
int idx, i, j;
- logf (LOG_DEBUG, "add %f", score);
for (i = 0; i<info->no_rec; i++)
{
idx = info->sort_idx[i];
info->sort_idx[j] = info->sort_idx[j+1];
info->sort_idx[j] = idx; /* allocate sort entry */
}
- info->sysno_idx[info->sysno_idx_p] = idx;
- if (++(info->sysno_idx_p) == info->max_rec)
- info->sysno_idx_p = 0;
-
memcpy (info->key_buf + idx*info->key_size, key, info->key_size);
info->score_buf[idx] = score;
}
+
+static struct rset_rel_info *qsort_info;
+
+static int qcomp (const void *p1, const void *p2)
+{
+ int i1 = *(int*) p1;
+ int i2 = *(int*) p2;
+
+ return qsort_info->cmp (qsort_info->key_buf + i1*qsort_info->key_size,
+ qsort_info->key_buf + i2*qsort_info->key_size);
+}
+
static void relevance (struct rset_rel_info *info, rset_relevance_parms *parms)
{
char **isam_buf;
/* if value is in the top score, then save it - don't emit yet */
add_rec (info, score, isam_tmp_buf);
}
+ for (i = 0; i<info->no_rec; i++)
+ info->sysno_idx[i] = i;
+ qsort_info = info;
+ qsort (info->sysno_idx, info->no_rec, sizeof(*info->sysno_idx), qcomp);
for (i = 0; i<parms->no_isam_positions; i++)
{
is_pt_free (isam_pt[i]);
xfree (wgt);
}
-static rset_control *r_create (const struct rset_control *sel, void *parms)
+static void *r_create (const struct rset_control *sel, void *parms)
{
- rset_control *newct;
rset_relevance_parms *r_parms = parms;
struct rset_rel_info *info;
- newct = xmalloc(sizeof(*newct));
- memcpy(newct, sel, sizeof(*sel));
- newct->buf = xmalloc (sizeof(struct rset_rel_info));
-
- info = newct->buf;
+ info = xmalloc (sizeof(struct rset_rel_info));
info->key_size = r_parms->key_size;
assert (info->key_size > 1);
info->max_rec = r_parms->max_rec;
info->score_buf = xmalloc (sizeof(*info->score_buf) * info->max_rec);
info->sort_idx = xmalloc (sizeof(*info->sort_idx) * info->max_rec);
info->sysno_idx = xmalloc (sizeof(*info->sysno_idx) * info->max_rec);
- info->sysno_idx_p = 0;
info->no_rec = 0;
info->rfd_list = NULL;
relevance (info, r_parms);
- return newct;
+ return info;
}
-static RSFD r_open (rset_control *ct, int flag)
+static RSFD r_open (RSET ct, int flag)
{
struct rset_rel_rfd *rfd;
struct rset_rel_info *info = ct->buf;
rfd = xmalloc (sizeof(*rfd));
rfd->flag = flag;
rfd->next = info->rfd_list;
- info->rfd_list = rfd;
- rfd->position = info->no_rec;
rfd->info = info;
+ info->rfd_list = rfd;
+ r_rewind (rfd);
return rfd;
}
assert (0);
}
-static void r_delete (rset_control *ct)
+static void r_delete (RSET ct)
{
struct rset_rel_info *info = ct->buf;
{
struct rset_rel_rfd *p = rfd;
struct rset_rel_info *info = p->info;
-
- p->position = info->no_rec;
+
+ if (p->flag & RSETF_SORT_RANK)
+ p->position = info->no_rec;
+ else
+ p->position = 0;
}
-static int r_count (rset_control *ct)
+static int r_count (RSET ct)
{
struct rset_rel_info *info = ct->buf;
struct rset_rel_rfd *p = rfd;
struct rset_rel_info *info = p->info;
- if (p->position <= 0)
- return 0;
- --(p->position);
+ if (p->flag & RSETF_SORT_RANK)
+ {
+ if (p->position <= 0)
+ return 0;
+ --(p->position);
+ p->last_read_pos = info->sort_idx[p->position];
+ }
+ else
+ {
+ if (p->position == info->no_rec)
+ return 0;
+ p->last_read_pos = info->sysno_idx[p->position];
+ ++(p->position);
+ }
memcpy ((char*) buf,
- info->key_buf + info->key_size * info->sort_idx[p->position],
+ info->key_buf + info->key_size * p->last_read_pos,
info->key_size);
return 1;
}
struct rset_rel_rfd *p = rfd;
struct rset_rel_info *info = p->info;
- if (p->position < 0)
- return 0;
- *score = (int) (1000*info->score_buf[info->sort_idx[p->position]]);
+ *score = (int) (1000*info->score_buf[p->last_read_pos]);
return 1;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: rstemp.c,v $
- * Revision 1.14 1995-10-10 14:00:04 adam
+ * Revision 1.15 1995-10-12 12:41:58 adam
+ * Private info (buf) moved from struct rset_control to struct rset.
+ * Bug fixes in relevance.
+ *
+ * Revision 1.14 1995/10/10 14:00:04 adam
* Function rset_open changed its wflag parameter to general flags.
*
* Revision 1.13 1995/10/06 14:38:06 adam
#include <alexutil.h>
#include <rstemp.h>
-static rset_control *r_create(const struct rset_control *sel, void *parms);
-static RSFD r_open (rset_control *ct, int flag);
+static void *r_create(const struct rset_control *sel, void *parms);
+static RSFD r_open (RSET ct, int flag);
static void r_close (RSFD rfd);
-static void r_delete (rset_control *ct);
+static void r_delete (RSET ct);
static void r_rewind (RSFD rfd);
-static int r_count (rset_control *ct);
+static int r_count (RSET ct);
static int r_read (RSFD rfd, void *buf);
static int r_write (RSFD rfd, const void *buf);
static int r_score (RSFD rfd, int *score);
static const rset_control control =
{
"Temporary set",
- 0,
r_create,
r_open,
r_close,
struct rset_temp_rfd *next;
};
-static struct rset_control *r_create(const struct rset_control *sel,
- void *parms)
+static void *r_create(const struct rset_control *sel, void *parms)
{
- rset_control *newct;
rset_temp_parms *temp_parms = parms;
struct rset_temp_info *info;
- newct = xmalloc(sizeof(*newct));
- memcpy(newct, sel, sizeof(*sel));
- newct->buf = xmalloc (sizeof(struct rset_temp_info));
- info = newct->buf;
-
+ info = xmalloc (sizeof(struct rset_temp_info));
info->fd = -1;
info->fname = NULL;
info->key_size = temp_parms->key_size;
info->pos_buf = 0;
info->dirty = 0;
- return newct;
+ return info;
}
-static RSFD r_open (struct rset_control *ct, int flag)
+static RSFD r_open (RSET ct, int flag)
{
struct rset_temp_info *info = ct->buf;
struct rset_temp_rfd *rfd;
}
}
-static void r_delete (struct rset_control *ct)
+static void r_delete (RSET ct)
{
struct rset_temp_info *info = ct->buf;
r_reread (rfd);
}
-static int r_count (struct rset_control *ct)
+static int r_count (RSET ct)
{
struct rset_temp_info *info = ct->buf;