From 5c7ad71f534d092eaf97f04dd39c5e874e0d45b0 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 12 Oct 1995 12:41:55 +0000 Subject: [PATCH] Private info (buf) moved from struct rset_control to struct rset. Bug fixes in relevance. --- rset/rsbool.c | 35 ++++++++++------------ rset/rset.c | 14 +++++---- rset/rsisam.c | 34 ++++++++++----------- rset/rsnull.c | 30 +++++++++---------- rset/rsrel.c | 92 +++++++++++++++++++++++++++++++++++---------------------- rset/rstemp.c | 33 ++++++++++----------- 6 files changed, 125 insertions(+), 113 deletions(-) diff --git a/rset/rsbool.c b/rset/rsbool.c index ba61fc6..d77d259 100644 --- a/rset/rsbool.c +++ b/rset/rsbool.c @@ -4,7 +4,11 @@ * 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 @@ -36,12 +40,12 @@ #include #include -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); @@ -51,7 +55,6 @@ static int r_score (RSFD rfd, int *score); static const rset_control control_and = { "AND set type", - 0, r_create, r_open, r_close, @@ -66,7 +69,6 @@ static const rset_control control_and = static const rset_control control_or = { "OR set type", - 0, r_create, r_open, r_close, @@ -81,7 +83,6 @@ static const rset_control control_or = static const rset_control control_not = { "NOT set type", - 0, r_create, r_open, r_close, @@ -117,25 +118,21 @@ struct rset_bool_rfd { 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; @@ -145,6 +142,7 @@ static RSFD r_open (rset_control *ct, int flag) 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; @@ -179,13 +177,12 @@ static void r_close (RSFD 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) @@ -200,7 +197,7 @@ 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; } diff --git a/rset/rset.c b/rset/rset.c index 0776cb2..5050a1d 100644 --- a/rset/rset.c +++ b/rset/rset.c @@ -4,7 +4,11 @@ * 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 @@ -36,14 +40,14 @@ RSET rset_create(const rset_control *sel, void *parms) 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); } diff --git a/rset/rsisam.c b/rset/rsisam.c index 40b6aa4..249a763 100644 --- a/rset/rsisam.c +++ b/rset/rsisam.c @@ -4,7 +4,11 @@ * 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 @@ -47,12 +51,12 @@ #include #include -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); @@ -60,7 +64,6 @@ static int r_score (RSFD rfd, int *score); static const rset_control control = { "ISAM set type", - 0, r_create, r_open, r_close, @@ -86,25 +89,19 @@ struct rset_isam_info { 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; @@ -140,14 +137,13 @@ static void r_close (RSFD rfd) 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) @@ -156,7 +152,7 @@ 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; } diff --git a/rset/rsnull.c b/rset/rsnull.c index c66704e..3cf371f 100644 --- a/rset/rsnull.c +++ b/rset/rsnull.c @@ -4,7 +4,11 @@ * 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 @@ -28,12 +32,12 @@ #include #include -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); @@ -41,7 +45,6 @@ static int r_score (RSFD rfd, int *score); static const rset_control control = { "NULL set type", - 0, r_create, r_open, r_close, @@ -55,16 +58,12 @@ static const rset_control control = 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) { @@ -78,9 +77,8 @@ static void r_close (RSFD rfd) { } -static void r_delete (rset_control *ct) +static void r_delete (RSET ct) { - xfree(ct); } static void r_rewind (RSFD rfd) @@ -88,7 +86,7 @@ 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; } diff --git a/rset/rsrel.c b/rset/rsrel.c index 923e10e..30dd4ed 100644 --- a/rset/rsrel.c +++ b/rset/rsrel.c @@ -4,7 +4,11 @@ * 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 @@ -34,12 +38,12 @@ #include #include -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); @@ -47,7 +51,6 @@ static int r_score (RSFD rfd, int *score); static const rset_control control = { "relevance set type", - 0, r_create, r_open, r_close, @@ -69,12 +72,12 @@ struct rset_rel_info { 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; @@ -85,7 +88,6 @@ static void add_rec (struct rset_rel_info *info, double score, void *key) { int idx, i, j; - logf (LOG_DEBUG, "add %f", score); for (i = 0; ino_rec; i++) { idx = info->sort_idx[i]; @@ -110,14 +112,22 @@ static void add_rec (struct rset_rel_info *info, double score, void *key) 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; @@ -187,6 +197,10 @@ static void relevance (struct rset_rel_info *info, rset_relevance_parms *parms) /* if value is in the top score, then save it - don't emit yet */ add_rec (info, score, isam_tmp_buf); } + for (i = 0; ino_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; ino_isam_positions; i++) { is_pt_free (isam_pt[i]); @@ -200,17 +214,12 @@ static void relevance (struct rset_rel_info *info, rset_relevance_parms *parms) 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; @@ -221,15 +230,14 @@ static rset_control *r_create (const struct rset_control *sel, void *parms) 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; @@ -242,9 +250,9 @@ static RSFD r_open (rset_control *ct, int flag) 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; } @@ -264,7 +272,7 @@ static void r_close (RSFD rfd) assert (0); } -static void r_delete (rset_control *ct) +static void r_delete (RSET ct) { struct rset_rel_info *info = ct->buf; @@ -281,11 +289,14 @@ static void r_rewind (RSFD rfd) { 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; @@ -297,11 +308,22 @@ static int r_read (RSFD rfd, void *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; } @@ -311,9 +333,7 @@ static int r_score (RSFD rfd, int *score) 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; } diff --git a/rset/rstemp.c b/rset/rstemp.c index 691ccb9..fafc908 100644 --- a/rset/rstemp.c +++ b/rset/rstemp.c @@ -4,7 +4,11 @@ * 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 @@ -60,12 +64,12 @@ #include #include -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); @@ -73,7 +77,6 @@ static int r_score (RSFD rfd, int *score); static const rset_control control = { "Temporary set", - 0, r_create, r_open, r_close, @@ -105,18 +108,12 @@ struct rset_temp_rfd { 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; @@ -127,10 +124,10 @@ static struct rset_control *r_create(const struct rset_control *sel, 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; @@ -213,7 +210,7 @@ static void r_close (RSFD rfd) } } -static void r_delete (struct rset_control *ct) +static void r_delete (RSET ct) { struct rset_temp_info *info = ct->buf; @@ -278,7 +275,7 @@ static void r_rewind (RSFD rfd) r_reread (rfd); } -static int r_count (struct rset_control *ct) +static int r_count (RSET ct) { struct rset_temp_info *info = ct->buf; -- 1.7.10.4