X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=dict%2Fdicttest.c;h=5538b497b53b487b21b0c48fe5df991a35f1c002;hb=1c3797bc503c1e7a109c8887d89d3ddda93bba71;hp=07e19f1d4755d746838d903c4ee9e5145f97b1ed;hpb=6c820cde24f590dcb4d88842af0f4a246a9e7c71;p=idzebra-moved-to-github.git diff --git a/dict/dicttest.c b/dict/dicttest.c index 07e19f1..5538b49 100644 --- a/dict/dicttest.c +++ b/dict/dicttest.c @@ -1,10 +1,32 @@ /* - * Copyright (C) 1994-1995, Index Data I/S + * Copyright (C) 1994-1999, Index Data * All rights reserved. * Sebastian Hammer, Adam Dickmeiss * * $Log: dicttest.c,v $ - * Revision 1.17 1995-12-06 17:48:30 adam + * Revision 1.23 2000-07-07 12:49:20 adam + * Optimized resultSetInsert{Rank,Sort}. + * + * Revision 1.22 1999/02/02 14:50:19 adam + * Updated WIN32 code specific sections. Changed header. + * + * Revision 1.21 1996/10/29 14:00:03 adam + * Page size given by DICT_DEFAULT_PAGESIZE in dict.h. + * + * Revision 1.20 1996/03/20 09:35:16 adam + * Function dict_lookup_grep got extra parameter, init_pos, which marks + * from which position in pattern approximate pattern matching should occur. + * + * Revision 1.19 1996/02/02 13:43:50 adam + * The public functions simply use char instead of Dict_char to represent + * search strings. Dict_char is used internally only. + * + * Revision 1.18 1996/02/01 20:39:52 adam + * Bug fix: insert didn't work on 8-bit characters due to unsigned char + * compares in dict_strcmp (strcmp) and signed Dict_char. Dict_char is + * unsigned now. + * + * Revision 1.17 1995/12/06 17:48:30 adam * Bug fix: delete didn't work. * * Revision 1.16 1995/10/09 16:18:31 adam @@ -68,13 +90,14 @@ #include #include +#include char *prog; static Dict dict; static int look_hits; -static int grep_handle (Dict_char *name, const char *info, void *client) +static int grep_handle (char *name, const char *info, void *client) { look_hits++; printf ("%s\n", name); @@ -83,11 +106,14 @@ static int grep_handle (Dict_char *name, const char *info, void *client) int main (int argc, char **argv) { + Res my_resource = 0; + BFiles bfs; const char *name = NULL; const char *inputfile = NULL; - const char *base = NULL; + const char *config = NULL; int do_delete = 0; int range = -1; + int srange = 0; int rw = 0; int infosize = 4; int cache = 10; @@ -104,17 +130,27 @@ int main (int argc, char **argv) if (argc < 2) { fprintf (stderr, "usage:\n " - " %s [-d] [-r n] [-u] [-g pat] [-s n] [-v n] [-i f] [-w]" - " [-c n] base file\n", + " %s [-d] [-r n] [-p n] [-u] [-g pat] [-s n] [-v n] [-i f]" + " [-w] [-c n] config file\n\n", prog); + fprintf (stderr, " -d delete instead of insert\n"); + fprintf (stderr, " -r n set regular match range\n"); + fprintf (stderr, " -p n set regular match start range\n"); + fprintf (stderr, " -u report if keys change during insert\n"); + fprintf (stderr, " -g p try pattern n (see -r)\n"); + fprintf (stderr, " -s n set info size to n (instead of 4)\n"); + fprintf (stderr, " -v n set logging level\n"); + fprintf (stderr, " -i f read file with words\n"); + fprintf (stderr, " -w insert/delete instead of lookup\n"); + fprintf (stderr, " -c n cache size (number of pages)\n"); exit (1); } - while ((ret = options ("dr:ug:s:v:i:wc:", argv, argc, &arg)) != -2) + while ((ret = options ("dr:p:ug:s:v:i:wc:", argv, argc, &arg)) != -2) { if (ret == 0) { - if (!base) - base = arg; + if (!config) + config = arg; else if (!name) name = arg; else @@ -133,6 +169,10 @@ int main (int argc, char **argv) { range = atoi (arg); } + else if (ret == 'p') + { + srange = atoi (arg); + } else if (ret == 'u') { unique = 1; @@ -161,18 +201,24 @@ int main (int argc, char **argv) exit (1); } } - if (!base || !name) + if (!config || !name) + { + logf (LOG_FATAL, "no config and/or dictionary specified"); + exit (1); + } + my_resource = res_open (config); + if (!my_resource) { - logf (LOG_FATAL, "no base and/or dictionary specified"); + logf (LOG_FATAL, "cannot open resource `%s'", config); exit (1); } - common_resource = res_open (base); - if (!common_resource) + bfs = bfs_create (res_get(my_resource, "register")); + if (!bfs) { - logf (LOG_FATAL, "cannot open resource `%s'", base); + logf (LOG_FATAL, "bfs_create fail"); exit (1); } - dict = dict_open (name, cache, rw); + dict = dict_open (bfs, name, cache, rw, 0); if (!dict) { logf (LOG_FATAL, "dict_open fail of `%s'", name); @@ -250,13 +296,17 @@ int main (int argc, char **argv) { look_hits = 0; dict_lookup_grep (dict, ipf_ptr, range, NULL, - &max_pos, grep_handle); + &max_pos, srange, grep_handle); if (look_hits) no_of_hits++; else no_of_misses++; } ++no_of_iterations; + if ((no_of_iterations % 10000) == 0) + { + printf ("."); fflush(stdout); + } ipf_ptr += (i-1); } } @@ -270,7 +320,7 @@ int main (int argc, char **argv) range = 0; logf (LOG_LOG, "Grepping '%s'", grep_pattern); dict_lookup_grep (dict, grep_pattern, range, NULL, &max_pos, - grep_handle); + srange, grep_handle); } if (rw) { @@ -293,6 +343,7 @@ int main (int argc, char **argv) logf (LOG_LOG, "No of misses.. %d", no_of_misses); } dict_close (dict); - res_close (common_resource); + bfs_destroy (bfs); + res_close (my_resource); return 0; }