]> git.ozlabs.org Git - ccan/blob - ccan/agar/test/negacycle.c
Merge Makefile rewrite into master
[ccan] / ccan / agar / test / negacycle.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 *negacycle_first_edge_r(const struct agar_graph *gr,
13                                           const void *nr)
14 {
15         return int2ptr(1);
16 }
17
18 static const void *negacycle_next_edge_r(const struct agar_graph *gr,
19                                          const void *nr, const void *e)
20 {
21         assert(ptr2int(e) == 1);
22         return NULL;
23 }
24
25 static int negacycle_edge_info_r(const struct agar_graph *gr,
26                                  const void *nr, const void *e,
27                                  struct agar_edge_info *eir)
28 {
29         int ni = ptr2int(nr);
30
31         assert(ptr2int(e) == 1);
32         eir->to = int2ptr((ni % 3) + 1);
33         if (ni == 3)
34                 eir->icost = -3;
35         return 0;
36 }
37
38 struct negacycle_graphr negacycle_graphr = {
39         AGAR_INIT_GRAPH(negacycle_first_edge_r,
40                         negacycle_next_edge_r,
41                         negacycle_edge_info_r),
42 };