* Sebastian Hammer, Adam Dickmeiss
*
* $Log: trunc.c,v $
- * Revision 1.13 1999-05-12 13:08:06 adam
+ * Revision 1.16 1999-11-30 13:48:03 adam
+ * Improved installation. Updated for inclusion of YAZ header files.
+ *
+ * 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
#include <stdio.h>
#include <assert.h>
+#define NEW_TRUNC 1
+
#include "zserver.h"
#include <rstemp.h>
+#include <rsnull.h>
+#include <rsisams.h>
+#if ZMBOL
#include <rsisam.h>
#include <rsisamc.h>
-#include <rsisams.h>
-#include <rsnull.h>
-
-#define NEW_TRUNC 1
-
#if NEW_TRUNC
#include <rsm_or.h>
#endif
+#endif
struct trunc_info {
int *ptr;
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;
}
static RSET rset_trunc_r (ZebraHandle zi, const char *term, int length,
- const char *flags, ISAM_P *isam_p, int from, int to,
+ const char *flags, ISAMS_P *isam_p, int from, int to,
int merge_chunk)
{
RSET result;
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)
{
xfree (rsfd);
heap_close (ti);
}
+#if ZMBOL
else if (zi->isam)
{
ISPT *ispt;
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);
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);
heap_close (ti);
xfree (ispt);
}
+#endif
else if (zi->isams)
{
ISAMS_PP *ispt;
int i;
struct trunc_info *ti;
- ispt = xmalloc (sizeof(*ispt) * (to-from));
+ ispt = (ISAMS_PP *) xmalloc (sizeof(*ispt) * (to-from));
ti = heap_init (to-from, sizeof(struct it_key),
key_compare_it);
return result;
}
+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;
+}
+
+#if ZMBOL
static int isam_trunc_cmp (const void *p1, const void *p2)
{
ISAM_P i1 = *(ISAM_P*) p1;
return d;
return isc_block (i1) - isc_block (i2);
}
+#endif
-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,
+RSET rset_trunc (ZebraHandle zi, ISAMS_P *isam_p, int no,
const char *term, int length, const char *flags)
{
logf (LOG_DEBUG, "rset_trunc no=%d", no);
- if (zi->isam)
+ 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->isams)
{
- if (no < 1)
- return rset_create (rset_kind_null, NULL);
- else if (no == 1)
+ 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);
+ }
+#if ZMBOL
+ else if (zi->isam)
+ {
+ 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)
- return rset_create (rset_kind_null, NULL);
- else 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);
- }
+#endif
else
{
logf (LOG_WARN, "Neither isam / isamc / isams set in rset_trunc");