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
27 * Merge neighbors into queue, keeping it sorted. "neighbors" is sorted,
28 * both by lower bound cost and then by secondary cost.
31 as_merge(struct as_data *adp, struct as_queue *head,
32 struct as_node **neighbors)
35 struct as_queue *pp; /* previous pointer */
36 struct as_queue *ip; /* insert pointer */
42 for (i = 0; neighbors[i]; i++) {
44 /* scan until qp points to a node we should go in front of */
45 while (qp && (qp->np->lbcost < np->lbcost)) {
49 /* check for equal lower bounds, and use secondary cost if = */
50 if (qp && qp->np->lbcost == np->lbcost) {
51 while (qp && (qp->np->lbcost == np->lbcost) &&
52 (qp->np->seccost < np->seccost)) {
57 AS_NEW_MALLOC(ip, struct as_queue, NULL);
58 /* if there was such a node, insert us in front of it */
67 } else { /* otherwise add us to end of queue */
78 as_setcinq(adp, np->c, ip);