]> git.pond.sub.org Git - empserver/blob - src/lib/as/as_stats.c
Indented with src/scripts/indent-emp.
[empserver] / src / lib / as / as_stats.c
1 /*
2  *  A* Search - A search library used in Empire to determine paths between
3  *              objects.
4  *  Copyright (C) 1990-1998 Phil Lapsley
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License as published by
8  *  the Free Software Foundation; either version 2 of the License, or
9  *  (at your option) any later version.
10  *
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU General Public License for more details.
15  *
16  *  You should have received a copy of the GNU General Public License
17  *  along with this program; if not, write to the Free Software
18  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20 #include <stdio.h>
21 #include "as.h"
22
23 #if !defined(lint) && !defined(SABER)
24 static char sccsid[] = "@(#)as_stats.c  1.2     11/13/90";
25 #endif /* not lint */
26
27 /*
28  * Print statistics on algorithm performance to the file pointer "fp".
29  */
30 void
31 as_stats(struct as_data *adp, FILE * fp)
32 {
33     int i;
34     int j;
35     int total_q;
36     int total_h;
37     struct as_queue *qp;
38     struct as_hash *hp;
39
40     fprintf(fp, "Statistics:\n");
41
42     fprintf(fp, "queue lengths:\n");
43     total_q = 0;
44     total_h = 0;
45     for (i = 0, qp = adp->head; qp; qp = qp->next)
46         i++;
47     fprintf(fp, "\tmain:\t%d\n", i);
48     total_q += i;
49     for (i = 0, qp = adp->tried; qp; qp = qp->next)
50         i++;
51     fprintf(fp, "\ttried:\t%d\n", i);
52     total_q += i;
53     for (i = 0, qp = adp->subsumed; qp; qp = qp->next)
54         i++;
55     fprintf(fp, "\tsubsumed:\t%d\n", i);
56     total_q += i;
57     fprintf(fp, "hash table statistics (size %d):\n", adp->hashsize);
58     for (i = 0; i < adp->hashsize; i++) {
59         for (j = 0, hp = adp->hashtab[i]; hp; hp = hp->next)
60             j++;
61         fprintf(fp, "\t%d\t%d\n", i, j);
62         total_h += j;
63     }
64     fprintf(fp, "\ttotal\t%d\n", total_h);
65     fprintf(fp, "approximate memory usage (bytes):\n");
66     fprintf(fp, "\tqueues\t%d\n",
67             (int)(total_q * sizeof(struct as_queue)));
68     fprintf(fp, "\tnodes\t%d\n", (int)(total_q * sizeof(struct as_node)));
69     fprintf(fp, "\thash ents\t%d\n",
70             (int)(total_h * sizeof(struct as_hash)));
71     fprintf(fp, "\ttotal\t%d\n",
72             (int)(total_q * sizeof(struct as_queue) +
73                   total_q * sizeof(struct as_node) +
74                   total_h * sizeof(struct as_hash)));
75 }