]> git.ozlabs.org Git - ccan/blob - ccan/agar/test/shortcut2.c
aff89a616419ea58191f3d70b9bb6db6d4752f11
[ccan] / ccan / agar / test / shortcut2.c
1 #include "config.h"
2
3 #include <assert.h>
4
5 #include <ccan/container_of/container_of.h>
6 #include <ccan/ptrint/ptrint.h>
7
8 #include <ccan/agar/agar.h>
9
10 #include "simple-graphr.h"
11
12 static const void *shortcut2_first_edge_r(const struct agar_graph *gr,
13                                           const void *nr)
14 {
15         int ni = ptr2int(nr);
16
17         switch (ni) {
18         case 1:
19         case 2:
20                 return int2ptr(1);
21
22         case 3:
23                 return NULL;
24
25         default:
26                 assert(0);
27         }
28 }
29
30 static const void *shortcut2_next_edge_r(const struct agar_graph *gr,
31                                          const void *nr, const void *e)
32 {
33         int ni = ptr2int(nr);
34         int index = ptr2int(e);
35
36         switch (ni) {
37         case 1:
38                 if (index == 1)
39                         return int2ptr(2);
40                 assert(index == 2);
41                 return NULL;
42
43         case 2:
44                 assert(index == 1);
45                 return NULL;
46
47         default:
48                 assert(0);
49         }
50 }
51
52 static int shortcut2_edge_info_r(const struct agar_graph *gr,
53                                  const void *nr, const void *e,
54                                  struct agar_edge_info *eir)
55 {
56         int ni = ptr2int(nr);
57         int index = ptr2int(e);
58
59         switch (ni) {
60         case 1:
61                 if (index == 1) {
62                         eir->to = int2ptr(3);
63                 } else {
64                         assert(index == 2);
65                         eir->to = int2ptr(2);
66                 }
67                 eir->icost = 2;
68                 break;
69
70         case 2:
71                 assert(index == 1);
72                 eir->to = int2ptr(3);
73                 eir->icost = -1;
74                 break;
75
76         default:
77                 assert(0);
78         }
79         return 0;
80 }
81
82 void shortcut2_graphr_init(struct shortcut2_graphr *s1gr)
83 {
84         agar_init_graph(&s1gr->gr, shortcut2_first_edge_r,
85                         shortcut2_next_edge_r,
86                         shortcut2_edge_info_r);
87 }