| 37 | } |
| 38 | |
| 39 | struct graph *graph_new(const tal_t *ctx, const size_t max_num_nodes, |
| 40 | const size_t max_num_arcs, const size_t arc_dual_bit) |
| 41 | { |
| 42 | struct graph *graph; |
| 43 | graph = tal(ctx, struct graph); |
| 44 | |
| 45 | graph->max_num_arcs = max_num_arcs; |
| 46 | graph->max_num_nodes = max_num_nodes; |
| 47 | graph->arc_dual_bit = arc_dual_bit; |
| 48 | |
| 49 | graph->arc_tail = tal_arr(graph, struct node, graph->max_num_arcs); |
| 50 | graph->node_adjacency_first = |
| 51 | tal_arr(graph, struct arc, graph->max_num_nodes); |
| 52 | graph->node_adjacency_next = |
| 53 | tal_arr(graph, struct arc, graph->max_num_arcs); |
| 54 | |
| 55 | /* initialize with invalid indexes so that we know these slots have |
| 56 | * never been used, eg. arc/node is newly created */ |
| 57 | for (size_t i = 0; i < graph->max_num_arcs; i++) |
| 58 | graph->arc_tail[i] = node_obj(INVALID_INDEX); |
| 59 | for (size_t i = 0; i < graph->max_num_nodes; i++) |
| 60 | graph->node_adjacency_first[i] = arc_obj(INVALID_INDEX); |
| 61 | for (size_t i = 0; i < graph->max_num_nodes; i++) |
| 62 | graph->node_adjacency_next[i] = arc_obj(INVALID_INDEX); |
| 63 | |
| 64 | return graph; |
| 65 | } |