]> git.pond.sub.org Git - empserver/blob - src/lib/as/as_init.c
(as_data): Use void * for userdata member and userdata parameter of
[empserver] / src / lib / as / as_init.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 <stdio.h>
24 #include <stdlib.h>
25 #include "as.h"
26
27 /*
28  * Return an as_data structure with the necessary fields filled in
29  * and space malloced.  Return NULL if malloc fails.
30  */
31 struct as_data *
32 as_init(int maxneighbors,
33         int hashsize,
34         int (*hashfunc)(struct as_coord),
35         int (*neighborfunc)(struct as_coord, struct as_coord *, void *),
36         double (*lbcostfunc)(struct as_coord, struct as_coord, void *),
37         double (*realcostfunc)(struct as_coord, struct as_coord, void *),
38         double (*seccostfunc)(struct as_coord, struct as_coord, void *),
39         void *userdata)
40 {
41     struct as_data *adp;
42
43     AS_NEW(adp, struct as_data, NULL);
44     AS_NEW_ARRAY(adp->neighbor_coords, struct as_coord,
45                  maxneighbors, NULL);
46     AS_NEW_ARRAY(adp->neighbor_nodes, struct as_node *,
47                  maxneighbors + 1, NULL);
48     AS_NEW_ARRAY(adp->hashtab, struct as_hash *, hashsize, NULL);
49
50     adp->maxneighbors = maxneighbors;
51     adp->hashsize = hashsize;
52     adp->hash = hashfunc;
53     adp->neighbor = neighborfunc;
54     adp->lbcost = lbcostfunc;
55     adp->realcost = realcostfunc;
56     adp->seccost = seccostfunc;
57     adp->userdata = userdata;
58
59     return adp;
60 }