]> git.ozlabs.org Git - ccan/blob - ccan/agar/test/shortcut1.c
efae316489cb86c3bc3c19a4959577fd45a83407
[ccan] / ccan / agar / test / shortcut1.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 *shortcut1_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 *shortcut1_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 shortcut1_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                         eir->icost = 3;
64                 } else {
65                         assert(index == 2);
66                         eir->to = int2ptr(2);
67                 }
68                 break;
69
70         case 2:
71                 assert(index == 1);
72                 eir->to = int2ptr(3);
73                 break;
74
75         default:
76                 assert(0);
77         }
78         return 0;
79 }
80
81 void shortcut1_graphr_init(struct shortcut1_graphr *s1gr)
82 {
83         agar_init_graph(&s1gr->gr, shortcut1_first_edge_r,
84                         shortcut1_next_edge_r,
85                         shortcut1_edge_info_r);
86 }