]> git.ozlabs.org Git - ccan/blob - ccan/agar/test/full.c
agar: Re-entrant Abstract Graph Algorithms
[ccan] / ccan / agar / 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 #include <ccan/ptrint/ptrint.h>
8
9 #include <ccan/agar/agar.h>
10
11 #include "simple-graphr.h"
12
13 const void *full_first_edge_r(const struct agar_graph *gr,
14                               const void *nr)
15 {
16         return int2ptr(1);
17 }
18
19 const void *full_next_edge_r(const struct agar_graph *gr,
20                              const void *nr, const void *e)
21 {
22         struct full_graphr *fgr = container_of(gr, struct full_graphr, gr);
23         int ni = ptr2int(e);
24
25         ni += 1;
26         if (ni <= fgr->nnodes)
27                 return int2ptr(ni);
28         else
29                 return NULL;
30 }
31
32 static int full_edge_info_r(const struct agar_graph *gr,
33                             const void *nr, const void *edge,
34                             struct agar_edge_info *eir)
35 {
36         eir->to = edge;
37         return 0;
38 }
39
40 void full_graphr_init(struct full_graphr *fgr, int nnodes)
41 {
42         fgr->nnodes = nnodes;
43         agar_init_graph(&fgr->gr, full_first_edge_r, full_next_edge_r,
44                         full_edge_info_r);
45 }