X-Git-Url: http://lists.indexdata.dk/cgi-bin?a=blobdiff_plain;f=isamb%2Ftstisamb.c;h=4103211742341c54d93e550893b22907e5128ba7;hb=4eaf00a0af4c40bd166e2224964319a58efafeaa;hp=08ff71e9ee7c30cc7d29c76812eee154eceb7ad8;hpb=97e5c7f8db1ea9f806bf4bca38dee837c32d2e6f;p=idzebra-moved-to-github.git diff --git a/isamb/tstisamb.c b/isamb/tstisamb.c index 08ff71e..4103211 100644 --- a/isamb/tstisamb.c +++ b/isamb/tstisamb.c @@ -1,6 +1,6 @@ -/* $Id: tstisamb.c,v 1.6 2004-06-03 00:24:12 adam Exp $ - Copyright (C) 1995,1996,1997,1998,1999,2000,2001,2002,2003,2004 - Index Data Aps +/* $Id: tstisamb.c,v 1.26 2006-12-07 21:13:56 adam Exp $ + Copyright (C) 1995-2006 + Index Data ApS This file is part of the Zebra server. @@ -15,27 +15,35 @@ 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_SYS_TIMES_H +#include +#endif +#if HAVE_SYS_TIME_H +#include +#endif + +#include #include -#include #include -#include +#include +#include #include static void log_item(int level, const void *b, const char *txt) { int x; memcpy(&x, b, sizeof(int)); - yaz_log(LOG_DEBUG, "%s %d", txt, x); + yaz_log(YLOG_DEBUG, "%s %d", txt, x); } static void log_pr(const char *txt) { - yaz_log(LOG_DEBUG, "%s", txt); + yaz_log(YLOG_DEBUG, "%s", txt); } int compare_item(const void *a, const void *b) @@ -44,15 +52,19 @@ int compare_item(const void *a, const void *b) 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(int mode) +void *code_start(void) { return 0; } -void code_item(int mode, void *p, char **dst, char **src) +void code_item(void *p, char **dst, const char **src) { memcpy (*dst, *src, sizeof(int)); (*dst) += sizeof(int); @@ -62,13 +74,17 @@ void code_item(int mode, void *p, char **dst, char **src) void code_reset(void *p) { } -void code_stop(int mode, void *p) +void code_stop(void *p) { } struct read_info { + int val; + int step; + int no; int max; + int insertMode; }; int code_read(void *vp, char **dst, int *insertMode) @@ -76,39 +92,193 @@ int code_read(void *vp, char **dst, int *insertMode) struct read_info *ri = (struct read_info *)vp; int x; - if (ri->no > ri->max) - exit(3); - if (ri->no == ri->max) + 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)++; - *insertMode = 1; + ri->val = ri->val + ri->step; + *insertMode = ri->insertMode; + +#if 0 + yaz_log(YLOG_LOG, "%d %5d", ri->insertMode, x); +#endif return 1; } +void bench_insert(ISAMB isb, int number_of_trees, + int number_of_rounds, int number_of_elements) +{ + ISAMC_I isamc_i; + ISAM_P *isamc_p = xmalloc(sizeof(ISAM_P) * number_of_trees); + struct read_info ri; + int round, i; + + for (i = 0; iidx < ri->max && ri->delta[ri->idx] == ri->level) + { + ri->idx++; + ri->level = 0; + } + if (ri->idx >= ri->max) + return 0; - isamc_p = isamb_merge (isb, 0 /* new list */ , &isamc_i); + 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); - /* read the entries */ - pp = isamb_pp_open (isb, isamc_p); + 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