00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include <config.h>
00022
00023 #include <stdlib.h>
00024 #include "as.h"
00025
00026
00027
00028
00029
00030 struct as_queue *
00031 as_merge(struct as_data *adp, struct as_queue *head,
00032 struct as_node **neighbors)
00033 {
00034 struct as_queue *qp;
00035 struct as_queue *pp;
00036 struct as_queue *ip;
00037 struct as_node *np;
00038 int i;
00039
00040 qp = head;
00041 pp = NULL;
00042 for (i = 0; neighbors[i]; i++) {
00043 np = neighbors[i];
00044
00045 while (qp && (qp->np->lbcost < np->lbcost)) {
00046 pp = qp;
00047 qp = qp->next;
00048 }
00049
00050 if (qp && qp->np->lbcost == np->lbcost) {
00051 while (qp && (qp->np->lbcost == np->lbcost) &&
00052 (qp->np->seccost < np->seccost)) {
00053 pp = qp;
00054 qp = qp->next;
00055 }
00056 }
00057 AS_NEW_MALLOC(ip, struct as_queue, NULL);
00058
00059 if (qp) {
00060 ip->prev = qp->prev;
00061 if (ip->prev)
00062 ip->prev->next = ip;
00063 ip->next = qp;
00064 qp->prev = ip;
00065 if (qp == head)
00066 head = ip;
00067 } else {
00068 ip->next = NULL;
00069 ip->prev = pp;
00070 if (ip->prev)
00071 ip->prev->next = ip;
00072 else {
00073 head = ip;
00074 }
00075 pp = ip;
00076 }
00077 ip->np = np;
00078 as_setcinq(adp, np->c, ip);
00079 np->step++;
00080 }
00081
00082 return head;
00083 }