Import of Empire 4.2.12
This commit is contained in:
commit
d8b7fdfae1
817 changed files with 126589 additions and 0 deletions
88
src/lib/as/as_delete.c
Normal file
88
src/lib/as/as_delete.c
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
* A* Search - A search library used in Empire to determine paths between
|
||||
* objects.
|
||||
* Copyright (C) 1990-1998 Phil Lapsley
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "as.h"
|
||||
|
||||
#if !defined(lint) && !defined(SABER)
|
||||
static char sccsid[] = "@(#)as_delete.c 1.5 11/13/90";
|
||||
#endif /* not lint */
|
||||
|
||||
static void as_free_queue(struct as_queue *queue);
|
||||
|
||||
/*
|
||||
* Free any dynamically allocated data stored in the as_data structure.
|
||||
*/
|
||||
void
|
||||
as_reset(struct as_data *adp)
|
||||
{
|
||||
|
||||
as_free_queue(adp->head);
|
||||
adp->head = NULL;
|
||||
as_free_queue(adp->tried);
|
||||
adp->tried = NULL;
|
||||
as_free_queue(adp->subsumed);
|
||||
adp->subsumed = NULL;
|
||||
as_free_hashtab(adp);
|
||||
as_free_path(adp->path);
|
||||
adp->path = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a queue (either the main, subsumed, or tried).
|
||||
*/
|
||||
static void
|
||||
as_free_queue(struct as_queue *queue)
|
||||
{
|
||||
struct as_queue *qp, *qp2;
|
||||
|
||||
for (qp = queue; qp; qp = qp2) {
|
||||
free((s_char *)qp->np);
|
||||
qp2 = qp->next;
|
||||
free((s_char *)qp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a path.
|
||||
*/
|
||||
void
|
||||
as_free_path(struct as_path *pp)
|
||||
{
|
||||
struct as_path *pp2;
|
||||
|
||||
for (; pp; pp = pp2) {
|
||||
pp2 = pp->next;
|
||||
free((s_char *)pp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Delete the as_data structure (which includes freeing its data).
|
||||
*/
|
||||
void
|
||||
as_delete(struct as_data *adp)
|
||||
{
|
||||
as_reset(adp);
|
||||
free((s_char *)adp->neighbor_coords);
|
||||
free((s_char *)adp->neighbor_nodes);
|
||||
free((s_char *)adp->hashtab);
|
||||
free((s_char *)adp);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue