X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=rset%2Frstemp.c;h=325faf211152eaf797b49bf02096d03bcd610cab;hb=9c50a60b4bd5de297f77866fd173c78a10328498;hp=6b29bb4266b9bb7fded40f4f4a984c2efde6f46b;hpb=48b764604b23e70fe0a354bdfa02dc6ff0bffced;p=idzebra-moved-to-github.git diff --git a/rset/rstemp.c b/rset/rstemp.c index 6b29bb4..325faf2 100644 --- a/rset/rstemp.c +++ b/rset/rstemp.c @@ -1,4 +1,4 @@ -/* $Id: rstemp.c,v 1.35 2003-03-31 21:53:40 adam Exp $ +/* $Id: rstemp.c,v 1.44 2004-08-24 08:52:30 heikki Exp $ Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003 Index Data Aps @@ -39,9 +39,10 @@ static RSFD r_open (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_count (RSET ct); -static int r_read (RSFD rfd, void *buf, int *term_index); +/* static int r_count (RSET ct);*/ +static int r_read (RSFD rfd, void *buf); static int r_write (RSFD rfd, const void *buf); +static void r_pos (RSFD rfd, double *current, double *total); static const struct rset_control control = { @@ -51,7 +52,8 @@ static const struct rset_control control = r_close, r_delete, r_rewind, - r_count, + rset_default_forward, + r_pos, r_read, r_write, }; @@ -68,7 +70,7 @@ struct rset_temp_info { size_t pos_buf; /* position of first byte in window */ size_t pos_border; /* position of last byte+1 in window */ int dirty; /* window is dirty */ - int hits; /* no of hits */ + zint hits; /* no of hits */ char *temp_path; int (*cmp)(const void *p1, const void *p2); struct rset_temp_rfd *rfd_list; @@ -77,9 +79,9 @@ struct rset_temp_info { struct rset_temp_rfd { struct rset_temp_info *info; struct rset_temp_rfd *next; - int *countp; void *buf; size_t pos_cur; /* current position in set */ + zint cur; /* number of the current hit */ }; static void *r_create(RSET ct, const struct rset_control *sel, void *parms) @@ -96,20 +98,17 @@ static void *r_create(RSET ct, const struct rset_control *sel, void *parms) info->pos_end = 0; info->pos_buf = 0; info->dirty = 0; - info->hits = -1; + info->hits = 0; info->cmp = temp_parms->cmp; info->rfd_list = NULL; if (!temp_parms->temp_path) - info->temp_path = NULL; + info->temp_path = NULL; else { - info->temp_path = (char *) xmalloc (strlen(temp_parms->temp_path)+1); - strcpy (info->temp_path, temp_parms->temp_path); + info->temp_path = (char *) xmalloc (strlen(temp_parms->temp_path)+1); + strcpy (info->temp_path, temp_parms->temp_path); } - ct->no_rset_terms = 1; - ct->rset_terms = (RSET_TERM *) xmalloc (sizeof(*ct->rset_terms)); - ct->rset_terms[0] = temp_parms->rset_term; return info; } @@ -137,8 +136,6 @@ static RSFD r_open (RSET ct, int flag) rfd->info = info; r_rewind (rfd); - rfd->countp = &ct->rset_terms[0]->count; - *rfd->countp = 0; rfd->buf = xmalloc (info->key_size); return rfd; @@ -187,7 +184,7 @@ static void r_flush (RSFD rfd, int mk) if (info->fname && info->fd != -1 && info->dirty) { size_t count; - int r; + int r; if (lseek (info->fd, info->pos_buf, SEEK_SET) == -1) { @@ -250,9 +247,7 @@ static void r_delete (RSET ct) xfree (info->fname); } if (info->temp_path) - xfree (info->temp_path); - rset_term_destroy (ct->rset_terms[0]); - xfree (ct->rset_terms); + xfree (info->temp_path); xfree (info); } @@ -267,7 +262,7 @@ static void r_reread (RSFD rfd) if (info->fname) { size_t count; - int r; + int r; info->pos_border = ((struct rset_temp_rfd *)rfd)->pos_cur + info->buf_size; @@ -304,16 +299,18 @@ static void r_rewind (RSFD rfd) ((struct rset_temp_rfd *)rfd)->pos_cur = 0; info->pos_buf = 0; r_reread (rfd); + ((struct rset_temp_rfd *)rfd)->cur=0; } +/* static int r_count (RSET ct) { struct rset_temp_info *info = (struct rset_temp_info *) ct->buf; return info->pos_end / info->key_size; } - -static int r_read (RSFD rfd, void *buf, int *term_index) +*/ +static int r_read (RSFD rfd, void *buf) { struct rset_temp_rfd *mrfd = (struct rset_temp_rfd*) rfd; struct rset_temp_info *info = mrfd->info; @@ -331,13 +328,7 @@ static int r_read (RSFD rfd, void *buf, int *term_index) memcpy (buf, info->buf_mem + (mrfd->pos_cur - info->pos_buf), info->key_size); mrfd->pos_cur = nc; - *term_index = 0; - - if (*mrfd->countp == 0 || (*info->cmp)(buf, mrfd->buf) > 1) - { - memcpy (mrfd->buf, buf, mrfd->info->key_size); - (*mrfd->countp)++; - } + mrfd->cur++; return 1; } @@ -361,5 +352,13 @@ static int r_write (RSFD rfd, const void *buf) mrfd->pos_cur = nc; if (nc > info->pos_end) info->pos_border = info->pos_end = nc; + info->hits++; return 1; } + +static void r_pos (RSFD rfd, double *current, double *total) +{ + struct rset_temp_rfd *mrfd = (struct rset_temp_rfd*) rfd; + *current=(double) mrfd->cur; + *total=(double) mrfd->info->hits; +}