src/lib/as/as_init.c

Go to the documentation of this file.
00001 /*
00002  *  A* Search - A search library used in Empire to determine paths between
00003  *              objects.
00004  *  Copyright (C) 1990-1998 Phil Lapsley
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 #include <config.h>
00022 
00023 #include <stdlib.h>
00024 #include "as.h"
00025 
00026 /*
00027  * Return an as_data structure with the necessary fields filled in
00028  * and space malloced.  Return NULL if malloc fails.
00029  */
00030 struct as_data *
00031 as_init(int maxneighbors,
00032         int hashsize,
00033         int (*hashfunc)(struct as_coord),
00034         int (*neighborfunc)(struct as_coord, struct as_coord *, void *),
00035         double (*lbcostfunc)(struct as_coord, struct as_coord, void *),
00036         double (*realcostfunc)(struct as_coord, struct as_coord, void *),
00037         double (*seccostfunc)(struct as_coord, struct as_coord, void *),
00038         void *userdata)
00039 {
00040     struct as_data *adp;
00041 
00042     AS_NEW(adp, struct as_data, NULL);
00043     AS_NEW_ARRAY(adp->neighbor_coords, struct as_coord,
00044                  maxneighbors, NULL);
00045     AS_NEW_ARRAY(adp->neighbor_nodes, struct as_node *,
00046                  maxneighbors + 1, NULL);
00047     AS_NEW_ARRAY(adp->hashtab, struct as_hash *, hashsize, NULL);
00048 
00049     adp->maxneighbors = maxneighbors;
00050     adp->hashsize = hashsize;
00051     adp->hash = hashfunc;
00052     adp->neighbor = neighborfunc;
00053     adp->lbcost = lbcostfunc;
00054     adp->realcost = realcostfunc;
00055     adp->seccost = seccostfunc;
00056     adp->userdata = userdata;
00057 
00058     return adp;
00059 }

Generated on Fri Mar 28 11:01:11 2008 for empserver by  doxygen 1.5.2