Renamed function.
[libfirm] / pbqp_edge.c
1 #include "adt/array.h"
2 #include "assert.h"
3
4 #include "kaps.h"
5 #include "matrix.h"
6 #include "pbqp_edge.h"
7 #include "pbqp_edge_t.h"
8 #include "pbqp_node.h"
9 #include "pbqp_node_t.h"
10 #include "pbqp_t.h"
11
12 pbqp_edge *alloc_edge(pbqp *pbqp, int src_index, int tgt_index, pbqp_matrix *costs)
13 {
14         if (tgt_index < src_index) {
15                 return alloc_edge(pbqp, tgt_index, src_index, costs);
16         }
17
18         pbqp_edge *edge = obstack_alloc(&pbqp->obstack, sizeof(*edge));
19         assert(edge);
20
21         pbqp_node *src_node = get_node(pbqp, src_index);
22         assert(src_node);
23
24         pbqp_node *tgt_node = get_node(pbqp, tgt_index);
25         assert(tgt_node);
26
27         edge->costs = pbqp_matrix_copy(pbqp, costs);
28
29         /*
30          * Connect edge with incident nodes. Since the edge is allocated, we know
31          * that it don't appear in the edge lists of the nodes.
32          */
33         ARR_APP1(pbqp_edge *, src_node->edges, edge);
34         edge->src = src_index;
35         ARR_APP1(pbqp_edge *, tgt_node->edges, edge);
36         edge->tgt = tgt_index;
37
38         return edge;
39 }