-/* $Id: tstisamb.c,v 1.12 2004-12-08 14:02:37 adam Exp $
- Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004
- Index Data Aps
+/* $Id: tstisamb.c,v 1.19 2005-03-21 17:20:54 adam Exp $
+ Copyright (C) 1995-2005
+ Index Data ApS
This file is part of the Zebra server.
02111-1307, USA.
*/
+#include <stdlib.h>
#include <string.h>
+#include <yaz/log.h>
#include <yaz/xmalloc.h>
-#include <yaz/ylog.h>
#include <idzebra/isamb.h>
#include <assert.h>
memcpy(&ia, a, sizeof(int));
memcpy(&ib, b, sizeof(int));
- return ia - ib;
+ if (ia > ib)
+ return 1;
+ if (ia < ib)
+ return -1;
+ return 0;
}
void *code_start()
memcpy (*dst, &x, sizeof(int));
(*dst)+=sizeof(int);
- ri->no += ri->step;
+ ri->no = ri->no + ri->step;
*insertMode = ri->insertMode;
return 1;
}
-void tst_forward(ISAMB isb, int n)
+void tst_insert(ISAMB isb, int n)
{
ISAMC_I isamc_i;
ISAMC_P isamc_p;
struct read_info ri;
- int i;
ISAMB_PP pp;
+ char key_buf[10];
+ int nerrs = 0;
/* insert a number of entries */
ri.no = 0;
isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i);
/* read the entries */
- pp = isamb_pp_open (isb, isamc_p, 2);
-
- for (i = 0; i<ri.max; i +=2 )
+ pp = isamb_pp_open (isb, isamc_p, 1);
+
+ ri.no = 0;
+ while(isamb_pp_read (pp, key_buf))
{
- int x = -1;
- int xu = i;
- isamb_pp_forward(pp, &x, &xu);
- if (x != xu && xu != x+1)
+ int x;
+ memcpy (&x, key_buf, sizeof(int));
+ if (x != ri.no)
{
- yaz_log(YLOG_WARN, "isamb_pp_forward (1). Got %d (expected %d)",
- x, xu);
- exit(4);
+ yaz_log(YLOG_WARN, "isamb_pp_read. n=%d Got %d (expected %d)",
+ n, x, ri.no);
+ nerrs++;
}
+ else if (nerrs)
+ yaz_log(YLOG_LOG, "isamb_pp_read. n=%d Got %d",
+ n, x);
+
ri.no++;
}
- isamb_pp_close(pp);
-
- pp = isamb_pp_open (isb, isamc_p, 2);
- for (i = 0; i<ri.max; i += 100)
+ if (ri.no != ri.max)
{
- int x = -1;
- int xu = i;
- isamb_pp_forward(pp, &x, &xu);
- if (x != xu && xu != x+1)
- {
- yaz_log(YLOG_WARN, "isamb_pp_forward (2). Got %d (expected %d)",
- x, xu);
- exit(4);
- }
- ri.no++;
+ yaz_log(YLOG_WARN, "ri.max != ri.max (%d != %d)", ri.no, ri.max);
+ nerrs++;
}
+ isamb_dump(isb, isamc_p, log_pr);
isamb_pp_close(pp);
- isamb_unlink(isb, isamc_p);
+ if (nerrs)
+ exit(3);
+ /* delete a number of entries (even ones) */
+ ri.no = 0;
+ ri.step = 2;
+ ri.max = n;
+ ri.insertMode = 0;
+
+ isamc_i.clientData = &ri;
+ isamc_i.read_item = code_read;
+
+ isamc_p = isamb_merge (isb, isamc_p , &isamc_i);
+
+ /* delete a number of entries (odd ones) */
+ ri.no = 1;
+ ri.step = 2;
+ ri.max = n;
+ ri.insertMode = 0;
+
+ isamc_i.clientData = &ri;
+ isamc_i.read_item = code_read;
+
+ isamc_p = isamb_merge (isb, isamc_p , &isamc_i);
+
+ if (isamc_p)
+ {
+ yaz_log(YLOG_WARN, "isamb_merge did not return empty list");
+ exit(3);
+ }
}
-void tst_insert(ISAMB isb, int n)
+void tst_forward(ISAMB isb, int n)
{
ISAMC_I isamc_i;
ISAMC_P isamc_p;
struct read_info ri;
+ int i;
ISAMB_PP pp;
- char key_buf[10];
/* insert a number of entries */
ri.no = 0;
isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i);
/* read the entries */
- pp = isamb_pp_open (isb, isamc_p, 2);
+ pp = isamb_pp_open (isb, isamc_p, 1);
- ri.no = 0;
- while(isamb_pp_read (pp, key_buf))
+ for (i = 0; i<ri.max; i +=2 )
{
- int x;
- memcpy (&x, key_buf, sizeof(int));
- if (x != ri.no)
+ int x = -1;
+ int xu = i;
+ isamb_pp_forward(pp, &x, &xu);
+ if (x != xu && xu != x+1)
{
- yaz_log(YLOG_WARN, "isamb_pp_read. Got %d (expected %d)",
- x, ri.no);
- exit(3);
+ yaz_log(YLOG_WARN, "isamb_pp_forward (1). Got %d (expected %d)",
+ x, xu);
+ exit(4);
}
ri.no++;
}
- if (ri.no != ri.max)
+ isamb_pp_close(pp);
+
+ pp = isamb_pp_open (isb, isamc_p, 1);
+ for (i = 0; i<ri.max; i += 100)
{
- yaz_log(YLOG_WARN, "ri.max != ri.max (%d != %d)", ri.no, ri.max);
- exit(3);
+ int x = -1;
+ int xu = i;
+ isamb_pp_forward(pp, &x, &xu);
+ if (x != xu && xu != x+1)
+ {
+ yaz_log(YLOG_WARN, "isamb_pp_forward (2). Got %d (expected %d)",
+ x, xu);
+ exit(4);
+ }
+ ri.no++;
}
isamb_pp_close(pp);
- isamb_dump(isb, isamc_p, log_pr);
+ isamb_unlink(isb, isamc_p);
+}
- /* delete a number of entries (even ones) */
- ri.no = 0;
- ri.step = 2;
- ri.max = n;
- ri.insertMode = 0;
+void tst_x(ISAMB isb)
+{
+ ISAMC_I isamc_i;
+ ISAMB_P isamb_p = 0;
+ struct read_info ri;
isamc_i.clientData = &ri;
isamc_i.read_item = code_read;
-
- isamc_p = isamb_merge (isb, isamc_p , &isamc_i);
+ ri.no = 1000;
+ ri.step = 1;
+ ri.max = 1500;
+
+ isamb_p = isamb_merge (isb, isamb_p , &isamc_i);
- /* delete a number of entries (odd ones) */
ri.no = 1;
- ri.step = 2;
- ri.max = n;
- ri.insertMode = 0;
+ ri.step = 1;
+ ri.max = 500;
- isamc_i.clientData = &ri;
- isamc_i.read_item = code_read;
-
- isamc_p = isamb_merge (isb, isamc_p , &isamc_i);
+ isamb_p = isamb_merge (isb, isamb_p , &isamc_i);
+}
- if (isamc_p)
+void tst_append(ISAMB isb, int n)
+{
+ ISAMC_I isamc_i;
+ ISAMB_P isamb_p = 0;
+ struct read_info ri;
+ int i;
+ int chunk = 10;
+
+ for (i = 0; i < n; i += chunk)
{
- yaz_log(YLOG_WARN, "isamb_merge did not return empty list");
- exit(3);
+ /* insert a number of entries */
+ ri.no = 0;
+ ri.step = 1;
+ ri.max = i + chunk;
+ ri.insertMode = 1;
+
+ isamc_i.clientData = &ri;
+ isamc_i.read_item = code_read;
+
+ isamb_p = isamb_merge (isb, isamb_p , &isamc_i);
}
}
tst_insert(isb, 100);
tst_insert(isb, 500);
tst_insert(isb, 10000);
+
tst_forward(isb, 10000);
+
+ tst_x(isb);
+
+ tst_append(isb, 1000);
/* close isam handle */
isamb_close(isb);