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