* Sebastian Hammer, Adam Dickmeiss
*
* $Log: trunc.c,v $
- * Revision 1.12 1999-02-02 14:51:10 adam
+ * Revision 1.15 1999-07-20 13:59:18 adam
+ * Fixed bug that occurred when phrases had 0 hits.
+ *
+ * Revision 1.14 1999/05/26 07:49:13 adam
+ * C++ compilation.
+ *
+ * Revision 1.13 1999/05/12 13:08:06 adam
+ * First version of ISAMS.
+ *
+ * Revision 1.12 1999/02/02 14:51:10 adam
* Updated WIN32 code specific sections. Changed header.
*
* Revision 1.11 1998/03/25 13:48:02 adam
#include <rstemp.h>
#include <rsisam.h>
#include <rsisamc.h>
+#include <rsisams.h>
#include <rsnull.h>
#define NEW_TRUNC 1
int (*cmp)(const void *p1,
const void *p2))
{
- struct trunc_info *ti = xmalloc (sizeof(*ti));
+ struct trunc_info *ti = (struct trunc_info *) xmalloc (sizeof(*ti));
int i;
++size;
ti->heapnum = 0;
ti->keysize = key_size;
ti->cmp = cmp;
- ti->indx = xmalloc (size * sizeof(*ti->indx));
- ti->heap = xmalloc (size * sizeof(*ti->heap));
- ti->ptr = xmalloc (size * sizeof(*ti->ptr));
- ti->swapbuf = xmalloc (ti->keysize);
- ti->tmpbuf = xmalloc (ti->keysize);
- ti->buf = xmalloc (size * ti->keysize);
+ ti->indx = (int *) xmalloc (size * sizeof(*ti->indx));
+ ti->heap = (char **) xmalloc (size * sizeof(*ti->heap));
+ ti->ptr = (int *) xmalloc (size * sizeof(*ti->ptr));
+ ti->swapbuf = (char *) xmalloc (ti->keysize);
+ ti->tmpbuf = (char *) xmalloc (ti->keysize);
+ ti->buf = (char *) xmalloc (size * ti->keysize);
for (i = size; --i >= 0; )
{
ti->ptr[i] = i;
int rscur = 0;
int rsmax = (to-from)/i_add + 1;
- rset = xmalloc (sizeof(*rset) * rsmax);
- rsfd = xmalloc (sizeof(*rsfd) * rsmax);
+ rset = (RSET *) xmalloc (sizeof(*rset) * rsmax);
+ rsfd = (RSFD *) xmalloc (sizeof(*rsfd) * rsmax);
for (i = from; i < to; i += i_add)
{
int i;
struct trunc_info *ti;
- ispt = xmalloc (sizeof(*ispt) * (to-from));
+ ispt = (ISPT *) xmalloc (sizeof(*ispt) * (to-from));
ti = heap_init (to-from, sizeof(struct it_key),
key_compare_it);
heap_close (ti);
xfree (ispt);
}
- else
+ else if (zi->isamc)
{
ISAMC_PP *ispt;
int i;
struct trunc_info *ti;
- ispt = xmalloc (sizeof(*ispt) * (to-from));
+ ispt = (ISAMC_PP *) xmalloc (sizeof(*ispt) * (to-from));
ti = heap_init (to-from, sizeof(struct it_key),
key_compare_it);
#if 0
/* section that preserve all keys */
heap_delete (ti);
- if (is_readkey (ispt[n], ti->tmpbuf))
+ if (isc_pp_read (ispt[n], ti->tmpbuf))
heap_insert (ti, ti->tmpbuf, n);
else
isc_pp_close (ispt[n]);
heap_close (ti);
xfree (ispt);
}
+ else if (zi->isams)
+ {
+ ISAMS_PP *ispt;
+ int i;
+ struct trunc_info *ti;
+
+ ispt = (ISAMS_PP *) xmalloc (sizeof(*ispt) * (to-from));
+
+ ti = heap_init (to-from, sizeof(struct it_key),
+ key_compare_it);
+ for (i = to-from; --i >= 0; )
+ {
+ ispt[i] = isams_pp_open (zi->isams, isam_p[from+i]);
+ if (isams_pp_read (ispt[i], ti->tmpbuf))
+ heap_insert (ti, ti->tmpbuf, i);
+ else
+ isams_pp_close (ispt[i]);
+ }
+ while (ti->heapnum)
+ {
+ int n = ti->indx[ti->ptr[1]];
+
+ rset_write (result, result_rsfd, ti->heap[ti->ptr[1]]);
+ while (1)
+ {
+ if (!isams_pp_read (ispt[n], ti->tmpbuf))
+ {
+ heap_delete (ti);
+ isams_pp_close (ispt[n]);
+ break;
+ }
+ if ((*ti->cmp)(ti->tmpbuf, ti->heap[ti->ptr[1]]) > 1)
+ {
+ heap_delete (ti);
+ heap_insert (ti, ti->tmpbuf, n);
+ break;
+ }
+ }
+ }
+ heap_close (ti);
+ xfree (ispt);
+ }
rset_close (result, result_rsfd);
return result;
}
return isc_block (i1) - isc_block (i2);
}
+static int isams_trunc_cmp (const void *p1, const void *p2)
+{
+ ISAMS_P i1 = *(ISAMS_P*) p1;
+ ISAMS_P i2 = *(ISAMS_P*) p2;
+
+ return i1 - i2;
+}
+
RSET rset_trunc (ZebraHandle zi, ISAM_P *isam_p, int no,
const char *term, int length, const char *flags)
{
logf (LOG_DEBUG, "rset_trunc no=%d", no);
+ if (no < 1)
+ {
+ rset_null_parms parms;
+ parms.rset_term = rset_term_create (term, length, flags);
+ return rset_create (rset_kind_null, &parms);
+ }
if (zi->isam)
{
- if (no < 1)
- return rset_create (rset_kind_null, NULL);
- else if (no == 1)
+ if (no == 1)
{
rset_isam_parms parms;
}
else if (zi->isamc)
{
- if (no < 1)
- return rset_create (rset_kind_null, NULL);
- else if (no == 1)
+ if (no == 1)
{
rset_isamc_parms parms;
#endif
qsort (isam_p, no, sizeof(*isam_p), isamc_trunc_cmp);
}
+ else if (zi->isams)
+ {
+ if (no == 1)
+ {
+ rset_isams_parms parms;
+
+ parms.pos = *isam_p;
+ parms.is = zi->isams;
+ parms.rset_term = rset_term_create (term, length, flags);
+ return rset_create (rset_kind_isams, &parms);
+ }
+ qsort (isam_p, no, sizeof(*isam_p), isams_trunc_cmp);
+ }
else
{
- logf (LOG_WARN, "Neither isam nor isamc set in rset_trunc");
+ logf (LOG_WARN, "Neither isam / isamc / isams set in rset_trunc");
return rset_create (rset_kind_null, NULL);
}
return rset_trunc_r (zi, term, length, flags, isam_p, 0, no, 100);