]> git.pond.sub.org Git - empserver/blob - src/lib/as/as_delete.c
eab8b4be043f65951bbdaf3ec6dff7c77dec5eb3
[empserver] / src / lib / as / as_delete.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
21 #include <config.h>
22
23 #include <stdlib.h>
24 #include "as.h"
25
26 static void as_free_queue(struct as_queue *queue);
27
28 /*
29  * Free any dynamically allocated data stored in the as_data structure.
30  */
31 void
32 as_reset(struct as_data *adp)
33 {
34     as_free_queue(adp->head);
35     adp->head = NULL;
36     as_free_queue(adp->tried);
37     adp->tried = NULL;
38     as_free_queue(adp->subsumed);
39     adp->subsumed = NULL;
40     as_free_hashtab(adp);
41     as_free_path(adp->path);
42     adp->path = NULL;
43 }
44
45 /*
46  * Free a queue (either the main, subsumed, or tried).
47  */
48 static void
49 as_free_queue(struct as_queue *queue)
50 {
51     struct as_queue *qp, *qp2;
52
53     for (qp = queue; qp; qp = qp2) {
54         free(qp->np);
55         qp2 = qp->next;
56         free(qp);
57     }
58 }
59
60 /*
61  * Free a path.
62  */
63 void
64 as_free_path(struct as_path *pp)
65 {
66     struct as_path *pp2;
67
68     for (; pp; pp = pp2) {
69         pp2 = pp->next;
70         free(pp);
71     }
72 }
73
74 /*
75  * Delete the as_data structure (which includes freeing its data).
76  */
77 void
78 as_delete(struct as_data *adp)
79 {
80     as_reset(adp);
81     free(adp->neighbor_coords);
82     free(adp->neighbor_nodes);
83     free(adp->hashtab);
84     free(adp);
85 }