]> git.ozlabs.org Git - ccan/blob - ccan/aga/test/full.c
ccan/list: Add list_empty_nocheck
[ccan] / ccan / aga / test / full.c
1 #include "config.h"
2
3 #include <stdlib.h>
4 #include <assert.h>
5
6 #include <ccan/container_of/container_of.h>
7
8 #include <ccan/aga/aga.h>
9
10 #include "simple-graph.h"
11
12 struct aga_node *full_first_edge(const struct aga_graph *g,
13                                  const struct aga_node *node)
14 {
15         struct full_graph *fg = container_of(g, struct full_graph, sg.g);
16
17         return &fg->sg.nodes[1];
18 }
19
20 struct aga_node *full_next_edge(const struct aga_graph *g,
21                                 const struct aga_node *node,
22                                 struct aga_node *edge)
23 {
24         struct full_graph *fg = container_of(g, struct full_graph, sg.g);
25         int index = (edge - fg->sg.nodes);
26
27         if (index < fg->nnodes)
28                 return &fg->sg.nodes[index + 1];
29         else
30                 return NULL;
31 }
32
33 static int full_edge_info(const struct aga_graph *g,
34                           const struct aga_node *node,
35                           struct aga_node *edge,
36                           struct aga_edge_info *ei)
37 {
38         ei->to = edge;
39         return 0;
40 }
41
42 void full_graph_init(struct full_graph *fg, int nnodes)
43 {
44         assert(nnodes < MAX_NODES);
45         
46         fg->nnodes = nnodes;
47         simple_graph_init(&fg->sg, full_first_edge, full_next_edge,
48                           full_edge_info);
49 }