2 * A* Search - A search library used in Empire to determine paths between
4 * Copyright (C) 1990-1998 Phil Lapsley
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.
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.
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
24 #if !defined(lint) && !defined(SABER)
25 static char sccsid[] = "@(#)as_merge.c 1.2 11/13/90";
29 * Merge neighbors into queue, keeping it sorted. "neighbors" is sorted,
30 * both by lower bound cost and then by secondary cost.
33 as_merge(struct as_data *adp, struct as_queue *head,
34 struct as_node **neighbors)
37 struct as_queue *pp; /* previous pointer */
38 struct as_queue *ip; /* insert pointer */
44 for (i = 0; neighbors[i]; i++) {
46 /* scan until qp points to a node we should go in front of */
47 while (qp && (qp->np->lbcost < np->lbcost)) {
51 /* check for equal lower bounds, and use secondary cost if = */
52 if (qp && qp->np->lbcost == np->lbcost) {
53 while (qp && (qp->np->lbcost == np->lbcost) &&
54 (qp->np->seccost < np->seccost)) {
59 AS_NEW_MALLOC(ip, struct as_queue, NULL);
60 /* if there was such a node, insert us in front of it */
69 } else { /* otherwise add us to end of queue */
80 as_setcinq(adp, np->c, ip);