From 0245f556af399689056b7810ed0e3de93021ad4a Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Tue, 10 Oct 1995 13:59:23 +0000 Subject: [PATCH] Function rset_open changed its wflag parameter to general flags. --- include/rset.h | 11 ++++++++++- index/dir.c | 9 ++++++--- index/zrpn.c | 15 +++++++++------ index/zsets.c | 7 +++++-- rset/rsbool.c | 15 +++++++++------ rset/rsisam.c | 11 +++++++---- rset/rsnull.c | 11 +++++++---- rset/rsrel.c | 39 ++++++++++++++++++++++++++------------- rset/rstemp.c | 11 +++++++---- 9 files changed, 86 insertions(+), 43 deletions(-) diff --git a/include/rset.h b/include/rset.h index 79b4ae6..d793730 100644 --- a/include/rset.h +++ b/include/rset.h @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rset.h,v $ - * Revision 1.8 1995-10-06 14:37:53 adam + * Revision 1.9 1995-10-10 14:00:01 adam + * Function rset_open changed its wflag parameter to general flags. + * + * Revision 1.8 1995/10/06 14:37:53 adam * New result set method: r_score. * Local no (sysno) and score is transferred to retrieveCtrl. * @@ -61,6 +64,12 @@ typedef struct rset rset_control *control; } rset, *RSET; +#define RSETF_READ 0 +#define RSETF_WRITE 1 + +#define RSETF_SORT_SYSNO 0 +#define RSETF_SORT_RANK 2 + RSET rset_create(const rset_control *sel, void *parms); /* parameters? */ /* int rset_open(RSET rs, int wflag); */ diff --git a/index/dir.c b/index/dir.c index a13c74c..4c8bfb1 100644 --- a/index/dir.c +++ b/index/dir.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: dir.c,v $ - * Revision 1.7 1995-09-28 09:19:40 adam + * Revision 1.8 1995-10-10 13:59:23 adam + * Function rset_open changed its wflag parameter to general flags. + * + * Revision 1.7 1995/09/28 09:19:40 adam * xfree/xmalloc used everywhere. * Extract/retrieve method seems to work for text records. * @@ -43,7 +46,7 @@ struct dir_entry *dir_open (const char *rep) { DIR *dir; struct dirent *dent; - size_t entry_max = 50; + size_t entry_max = 500; size_t idx = 0; struct dir_entry *entry; @@ -65,7 +68,7 @@ struct dir_entry *dir_open (const char *rep) { struct dir_entry *entry_n; - entry_n = xmalloc (sizeof(*entry) * (entry_max + 400)); + entry_n = xmalloc (sizeof(*entry) * (entry_max + 1000)); memcpy (entry_n, entry, idx * sizeof(*entry)); xfree (entry); entry = entry_n; diff --git a/index/zrpn.c b/index/zrpn.c index 0073e10..9f27ad5 100644 --- a/index/zrpn.c +++ b/index/zrpn.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: zrpn.c,v $ - * Revision 1.24 1995-10-09 16:18:37 adam + * Revision 1.25 1995-10-10 13:59:24 adam + * Function rset_open changed its wflag parameter to general flags. + * + * Revision 1.24 1995/10/09 16:18:37 adam * Function dict_lookup_grep got extra client data parameter. * * Revision 1.23 1995/10/06 16:33:37 adam @@ -321,7 +324,7 @@ static RSET rset_trunc (ISAM isam, ISAM_P *isam_p, int from, int to, ispt = xmalloc (sizeof(*ispt) * (to-from)); parms.key_size = sizeof (struct it_key); result = rset_create (rset_kind_temp, &parms); - rsfd = rset_open (result, 1); + rsfd = rset_open (result, RSETF_WRITE|RSETF_SORT_SYSNO); ti = heap_init (to-from, sizeof(struct it_key), key_compare); @@ -574,12 +577,12 @@ static RSET rpn_prox (RSET *rset, int rset_no) for (i = 0; i static rset_control *r_create(const struct rset_control *sel, void *parms); -static RSFD r_open (rset_control *ct, int wflag); +static RSFD r_open (rset_control *ct, int flag); static void r_close (RSFD rfd); static void r_delete (rset_control *ct); static void r_rewind (RSFD rfd); @@ -132,12 +135,12 @@ static rset_control *r_create (const struct rset_control *sel, void *parms) return newct; } -static RSFD r_open (rset_control *ct, int wflag) +static RSFD r_open (rset_control *ct, int flag) { struct rset_bool_info *info = ct->buf; struct rset_bool_rfd *rfd; - if (wflag) + if (flag & RSETF_WRITE) { logf (LOG_FATAL, "bool set type is read-only"); return NULL; @@ -148,8 +151,8 @@ static RSFD r_open (rset_control *ct, int wflag) rfd->buf_l = xmalloc (info->key_size); rfd->buf_r = xmalloc (info->key_size); - rfd->rfd_l = rset_open (info->rset_l, wflag); - rfd->rfd_r = rset_open (info->rset_r, wflag); + rfd->rfd_l = rset_open (info->rset_l, flag); + rfd->rfd_r = rset_open (info->rset_r, flag); rfd->more_l = rset_read (info->rset_l, rfd->rfd_l, rfd->buf_l); rfd->more_r = rset_read (info->rset_r, rfd->rfd_r, rfd->buf_r); rfd->info = info; diff --git a/rset/rsisam.c b/rset/rsisam.c index ec1e203..40b6aa4 100644 --- a/rset/rsisam.c +++ b/rset/rsisam.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rsisam.c,v $ - * Revision 1.11 1995-10-06 14:38:05 adam + * 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 * New result set method: r_score. * Local no (sysno) and score is transferred to retrieveCtrl. * @@ -45,7 +48,7 @@ #include static rset_control *r_create(const struct rset_control *sel, void *parms); -static RSFD r_open (rset_control *ct, int wflag); +static RSFD r_open (rset_control *ct, int flag); static void r_close (RSFD rfd); static void r_delete (rset_control *ct); static void r_rewind (RSFD rfd); @@ -101,13 +104,13 @@ static rset_control *r_create(const struct rset_control *sel, void *parms) return newct; } -RSFD r_open (rset_control *ct, int wflag) +RSFD r_open (rset_control *ct, int flag) { struct rset_isam_info *info = ct->buf; struct rset_ispt_info *ptinfo; logf (LOG_DEBUG, "risam_open"); - if (wflag) + if (flag & RSETF_WRITE) { logf (LOG_FATAL, "ISAM set type is read-only"); return NULL; diff --git a/rset/rsnull.c b/rset/rsnull.c index 136617f..c66704e 100644 --- a/rset/rsnull.c +++ b/rset/rsnull.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rsnull.c,v $ - * Revision 1.4 1995-10-06 14:38:06 adam + * 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 * New result set method: r_score. * Local no (sysno) and score is transferred to retrieveCtrl. * @@ -26,7 +29,7 @@ #include static rset_control *r_create(const struct rset_control *sel, void *parms); -static RSFD r_open (rset_control *ct, int wflag); +static RSFD r_open (rset_control *ct, int flag); static void r_close (RSFD rfd); static void r_delete (rset_control *ct); static void r_rewind (RSFD rfd); @@ -61,9 +64,9 @@ static rset_control *r_create(const struct rset_control *sel, void *parms) return newct; } -static RSFD r_open (rset_control *ct, int wflag) +static RSFD r_open (rset_control *ct, int flag) { - if (wflag) + if (flag & RSETF_WRITE) { logf (LOG_FATAL, "NULL set type is read-only"); return NULL; diff --git a/rset/rsrel.c b/rset/rsrel.c index 0d52250..923e10e 100644 --- a/rset/rsrel.c +++ b/rset/rsrel.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rsrel.c,v $ - * Revision 1.5 1995-10-06 14:38:06 adam + * 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 * New result set method: r_score. * Local no (sysno) and score is transferred to retrieveCtrl. * @@ -32,7 +35,7 @@ #include static rset_control *r_create(const struct rset_control *sel, void *parms); -static RSFD r_open (rset_control *ct, int wflag); +static RSFD r_open (rset_control *ct, int flag); static void r_close (RSFD rfd); static void r_delete (rset_control *ct); static void r_rewind (RSFD rfd); @@ -63,15 +66,17 @@ struct rset_rel_info { int max_rec; int no_rec; int (*cmp)(const void *p1, const void *p2); - char *key_buf; - float *score_buf; - int *sort_idx; - + 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 */ struct rset_rel_rfd *rfd_list; }; struct rset_rel_rfd { int position; + int flag; struct rset_rel_rfd *next; struct rset_rel_info *info; }; @@ -88,23 +93,27 @@ static void add_rec (struct rset_rel_info *info, double score, void *key) break; } if (info->no_rec < info->max_rec) - { + { /* there is room for this entry */ for (j = info->no_rec; j > i; --j) info->sort_idx[j] = info->sort_idx[j-1]; idx = info->sort_idx[j] = info->no_rec; ++(info->no_rec); } else if (i == 0) - return; + return; /* score too low */ else { - idx = info->sort_idx[0]; + idx = info->sort_idx[0]; /* remove this entry */ --i; - for (j = 0; j < i; ++j) + for (j = 0; j < i; ++j) /* make room */ info->sort_idx[j] = info->sort_idx[j+1]; - info->sort_idx[j] = idx; + 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; } @@ -211,6 +220,8 @@ static rset_control *r_create (const struct rset_control *sel, void *parms) info->key_buf = xmalloc (info->key_size * info->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; @@ -218,17 +229,18 @@ static rset_control *r_create (const struct rset_control *sel, void *parms) return newct; } -static RSFD r_open (rset_control *ct, int wflag) +static RSFD r_open (rset_control *ct, int flag) { struct rset_rel_rfd *rfd; struct rset_rel_info *info = ct->buf; - if (wflag) + if (flag & RSETF_WRITE) { logf (LOG_FATAL, "relevance set type is read-only"); return NULL; } rfd = xmalloc (sizeof(*rfd)); + rfd->flag = flag; rfd->next = info->rfd_list; info->rfd_list = rfd; rfd->position = info->no_rec; @@ -260,6 +272,7 @@ static void r_delete (rset_control *ct) xfree (info->key_buf); xfree (info->score_buf); xfree (info->sort_idx); + xfree (info->sysno_idx); xfree (info); xfree (ct); } diff --git a/rset/rstemp.c b/rset/rstemp.c index 2103959..691ccb9 100644 --- a/rset/rstemp.c +++ b/rset/rstemp.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: rstemp.c,v $ - * Revision 1.13 1995-10-06 14:38:06 adam + * 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 * New result set method: r_score. * Local no (sysno) and score is transferred to retrieveCtrl. * @@ -58,7 +61,7 @@ #include static rset_control *r_create(const struct rset_control *sel, void *parms); -static RSFD r_open (rset_control *ct, int wflag); +static RSFD r_open (rset_control *ct, int flag); static void r_close (RSFD rfd); static void r_delete (rset_control *ct); static void r_rewind (RSFD rfd); @@ -127,7 +130,7 @@ static struct rset_control *r_create(const struct rset_control *sel, return newct; } -static RSFD r_open (struct rset_control *ct, int wflag) +static RSFD r_open (struct rset_control *ct, int flag) { struct rset_temp_info *info = ct->buf; struct rset_temp_rfd *rfd; @@ -135,7 +138,7 @@ static RSFD r_open (struct rset_control *ct, int wflag) assert (info->fd == -1); if (info->fname) { - if (wflag) + if (flag & RSETF_WRITE) info->fd = open (info->fname, O_RDWR|O_CREAT, 0666); else info->fd = open (info->fname, O_RDONLY); -- 1.7.10.4