Minor changes - removed include of ctype.h.
[idzebra-moved-to-github.git] / index / invstat.c
1 /*
2  * Copyright (C) 1994-1996, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: invstat.c,v $
7  * Revision 1.3  1996-06-04 10:18:58  adam
8  * Minor changes - removed include of ctype.h.
9  *
10  * Revision 1.2  1996/05/22  08:25:56  adam
11  * Minor change.
12  *
13  * Revision 1.1  1996/05/14 14:04:34  adam
14  * In zebraidx, the 'stat' command is improved. Statistics about ISAM/DICT
15  * is collected.
16  *
17  */
18 #include <stdio.h>
19 #include <assert.h>
20 #include <string.h>
21
22 #include "index.h"
23 #include "recindex.h"
24
25 struct inv_stat_info {
26     ISAM isam;
27     int no_dict_entries;
28     int no_dict_bytes;
29     int isam_bounds[20];
30     int isam_occurrences[20];
31     char tmp[128];
32 };
33
34 static int inv_stat_handle (char *name, const char *info, int pos,
35                             void *client)
36 {
37     int occur;
38     int i = 0;
39     struct inv_stat_info *stat_info = (struct inv_stat_info*) client;
40     ISPT ispt;
41     ISAM_P isam_p;
42
43     stat_info->no_dict_entries++;
44     stat_info->no_dict_bytes += strlen(name);
45
46     assert (*info == sizeof(ISAM_P));
47     memcpy (&isam_p, info+1, sizeof(ISAM_P));
48
49     ispt = is_position (stat_info->isam, isam_p);
50     
51     occur = is_numkeys (ispt);
52
53     is_pt_free (ispt);
54
55     while (occur > stat_info->isam_bounds[i] && stat_info->isam_bounds[i])
56         i++;
57     ++(stat_info->isam_occurrences[i]);
58
59     return 0;
60 }
61
62 void inv_prstat (const char *dict_fname, const char *isam_fname)
63 {
64     Dict dict;
65     ISAM isam;
66     Records records;
67     int i, prev;
68     int before = 0;
69     int after = 1000000000;
70     struct inv_stat_info stat_info;
71     char term_dict[2*IT_MAX_WORD+2];
72
73     term_dict[0] = 1;
74     term_dict[1] = 0;
75
76     dict = dict_open (dict_fname, 100, 0);
77     if (!dict)
78     {
79         logf (LOG_FATAL, "dict_open fail of `%s'", dict_fname);
80         exit (1);
81     }
82     isam = is_open (isam_fname, key_compare, 0, sizeof(struct it_key));
83     if (!isam)
84     {
85         logf (LOG_FATAL, "is_open fail of `%s'", isam_fname);
86         exit (1);
87     }
88     records = rec_open (0);
89
90     stat_info.no_dict_entries = 0;
91     stat_info.no_dict_bytes = 0;
92     stat_info.isam = isam;
93     stat_info.isam_bounds[0] = 1;
94     stat_info.isam_bounds[1] = 2;
95     stat_info.isam_bounds[2] = 3;
96     stat_info.isam_bounds[3] = 5;
97     stat_info.isam_bounds[4] = 10;
98     stat_info.isam_bounds[5] = 20;
99     stat_info.isam_bounds[6] = 30;
100     stat_info.isam_bounds[7] = 50;
101     stat_info.isam_bounds[8] = 100;
102     stat_info.isam_bounds[9] = 200;
103     stat_info.isam_bounds[10] = 5000;
104     stat_info.isam_bounds[11] = 10000;
105     stat_info.isam_bounds[12] = 20000;
106     stat_info.isam_bounds[13] = 50000;
107     stat_info.isam_bounds[14] = 100000;
108     stat_info.isam_bounds[15] = 200000;
109     stat_info.isam_bounds[16] = 500000;
110     stat_info.isam_bounds[17] = 1000000;
111     stat_info.isam_bounds[18] = 0;
112
113     for (i = 0; i<20; i++)
114         stat_info.isam_occurrences[i] = 0;
115
116     dict_scan (dict, term_dict, &before, &after, &stat_info, inv_stat_handle);
117
118     rec_close (&records);
119     dict_close (dict);
120     is_close (isam);
121
122     fprintf (stderr, "%d dictionary entries. %d bytes for strings\n",
123              stat_info.no_dict_entries, stat_info.no_dict_bytes);
124     fprintf (stderr, " size   occurrences\n");
125     prev = 1;
126     for (i = 0; stat_info.isam_bounds[i]; i++)
127     {
128         int here = stat_info.isam_bounds[i];
129         fprintf (stderr, "%7d-%-7d %7d\n",
130                  prev, here, stat_info.isam_occurrences[i]);
131         prev = here+1;
132     }
133     fprintf (stderr, "%7d-        %7d\n",
134              prev, stat_info.isam_occurrences[i]);
135 }