X-Git-Url: http://git.indexdata.com/?p=idzebra-moved-to-github.git;a=blobdiff_plain;f=isamb%2Ftstisamb.c;h=d48d837564b45251248a9737d44df8dae9fce054;hp=17f2a3889abc3992e13de7b78c2eee70ed5b4b4c;hb=d02c4c703a93e0ad3f4ccde4519879f1f57a6824;hpb=1e58ebd4607490d810c7396a4e87eb70d9528166 diff --git a/isamb/tstisamb.c b/isamb/tstisamb.c index 17f2a38..d48d837 100644 --- a/isamb/tstisamb.c +++ b/isamb/tstisamb.c @@ -1,8 +1,5 @@ -/* $Id: tstisamb.c,v 1.14 2005-01-02 18:51:31 adam Exp $ - Copyright (C) 1995-2005 - Index Data Aps - -This file is part of the Zebra server. +/* This file is part of the Zebra server. + Copyright (C) 1994-2011 Index Data Zebra is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free @@ -15,27 +12,40 @@ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Zebra; see the file LICENSE.zebra. If not, write to the -Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA -02111-1307, USA. +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#if HAVE_CONFIG_H +#include +#endif +#if HAVE_SYS_TIMES_H +#include +#endif +#if HAVE_SYS_TIME_H +#include +#endif + +#include #include #include #include #include #include +static int log_level = 0; + static void log_item(int level, const void *b, const char *txt) { int x; memcpy(&x, b, sizeof(int)); - yaz_log(YLOG_DEBUG, "%s %d", txt, x); + yaz_log(log_level, "%s %d", txt, x); } static void log_pr(const char *txt) { - yaz_log(YLOG_DEBUG, "%s", txt); + yaz_log(log_level, "%s", txt); } int compare_item(const void *a, const void *b) @@ -51,7 +61,7 @@ int compare_item(const void *a, const void *b) return 0; } -void *code_start() +void *code_start(void) { return 0; } @@ -71,8 +81,10 @@ void code_stop(void *p) } struct read_info { - int no; + int val; int step; + + int no; int max; int insertMode; }; @@ -84,58 +96,67 @@ int code_read(void *vp, char **dst, int *insertMode) if (ri->no >= ri->max) return 0; - x = ri->no; + ri->no++; + + x = ri->val; memcpy (*dst, &x, sizeof(int)); (*dst)+=sizeof(int); - ri->no = ri->no + ri->step; + ri->val = ri->val + ri->step; *insertMode = ri->insertMode; + +#if 0 + yaz_log(log_level, "%d %5d", ri->insertMode, x); +#endif return 1; } void tst_insert(ISAMB isb, int n) { ISAMC_I isamc_i; - ISAMC_P isamc_p; + ISAM_P isamc_p; struct read_info ri; ISAMB_PP pp; - char key_buf[10]; + char key_buf[20]; int nerrs = 0; /* insert a number of entries */ ri.no = 0; - ri.step = 1; ri.max = n; + + ri.val = 0; + ri.step = 1; ri.insertMode = 1; isamc_i.clientData = &ri; isamc_i.read_item = code_read; - - isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i); + + isamc_p = 0; /* new list */ + isamb_merge (isb, &isamc_p , &isamc_i); /* read the entries */ pp = isamb_pp_open (isb, isamc_p, 1); - ri.no = 0; + ri.val = 0; while(isamb_pp_read (pp, key_buf)) { int x; memcpy (&x, key_buf, sizeof(int)); - if (x != ri.no) + if (x != ri.val) { yaz_log(YLOG_WARN, "isamb_pp_read. n=%d Got %d (expected %d)", - n, x, ri.no); + n, x, ri.val); nerrs++; } else if (nerrs) - yaz_log(YLOG_LOG, "isamb_pp_read. n=%d Got %d", + yaz_log(log_level, "isamb_pp_read. n=%d Got %d", n, x); - ri.no++; + ri.val++; } - if (ri.no != ri.max) + if (ri.val != ri.max) { - yaz_log(YLOG_WARN, "ri.max != ri.max (%d != %d)", ri.no, ri.max); + yaz_log(YLOG_WARN, "ri.max != ri.max (%d != %d)", ri.val, ri.max); nerrs++; } isamb_dump(isb, isamc_p, log_pr); @@ -143,32 +164,36 @@ void tst_insert(ISAMB isb, int n) if (nerrs) exit(3); - return; /* delete a number of entries (even ones) */ ri.no = 0; + ri.max = n - n/2; + + ri.val = 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); + + isamb_merge (isb, &isamc_p , &isamc_i); /* delete a number of entries (odd ones) */ ri.no = 0; + ri.max = n/2; + + ri.val = 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); + + isamb_merge (isb, &isamc_p, &isamc_i); if (isamc_p) { - yaz_log(YLOG_WARN, "isamb_merge did not return empty list"); + yaz_log(YLOG_WARN, "isamb_merge did not return empty list n=%d", + n); exit(3); } } @@ -176,25 +201,28 @@ void tst_insert(ISAMB isb, int n) void tst_forward(ISAMB isb, int n) { ISAMC_I isamc_i; - ISAMC_P isamc_p; + ISAM_P isamc_p; struct read_info ri; int i; ISAMB_PP pp; /* insert a number of entries */ + ri.val = 0; + ri.max = n; + ri.no = 0; ri.step = 1; - ri.max = n; ri.insertMode = 1; isamc_i.clientData = &ri; isamc_i.read_item = code_read; - - isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i); + + isamc_p = 0; + isamb_merge (isb, &isamc_p, &isamc_i); /* read the entries */ pp = isamb_pp_open (isb, isamc_p, 1); - + for (i = 0; iidx < ri->max && ri->delta[ri->idx] == ri->level) + { + ri->idx++; + ri->level = 0; + } + if (ri->idx >= ri->max) + return 0; + + if (ri->delta[ri->idx] > 0) + { + ri->level++; + *insertMode = 1; + } + else + { + ri->level--; + *insertMode = 0; + } + x = ri->idx; + memcpy (*dst, &x, sizeof(int)); + (*dst)+=sizeof(int); + + yaz_log(YLOG_DEBUG, "%d %5d", *insertMode, x); + return 1; +} + +void tst_random(ISAMB isb, int n, int rounds, int max_dups) +{ + ISAM_P isamb_p = 0; + + int *freq = malloc(sizeof(int) * n); + int *delta = malloc(sizeof(int) * n); + int i, j; + for (i = 0; i