X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fagar%2Ftest%2Fshortcut1.c;fp=ccan%2Fagar%2Ftest%2Fshortcut1.c;h=efae316489cb86c3bc3c19a4959577fd45a83407;hb=13430d4e252edbe0c202237e5a956670da1efe0b;hp=0000000000000000000000000000000000000000;hpb=a2eaae42b58a44d6f88f5e20e4a7d7cdbde9edae;p=ccan diff --git a/ccan/agar/test/shortcut1.c b/ccan/agar/test/shortcut1.c new file mode 100644 index 00000000..efae3164 --- /dev/null +++ b/ccan/agar/test/shortcut1.c @@ -0,0 +1,86 @@ +#include "config.h" + +#include + +#include +#include + +#include + +#include "simple-graphr.h" + +static const void *shortcut1_first_edge_r(const struct agar_graph *gr, + const void *nr) +{ + int ni = ptr2int(nr); + + switch (ni) { + case 1: + case 2: + return int2ptr(1); + + case 3: + return NULL; + + default: + assert(0); + } +} + +static const void *shortcut1_next_edge_r(const struct agar_graph *gr, + const void *nr, const void *e) +{ + int ni = ptr2int(nr); + int index = ptr2int(e); + + switch (ni) { + case 1: + if (index == 1) + return int2ptr(2); + assert(index == 2); + return NULL; + + case 2: + assert(index == 1); + return NULL; + + default: + assert(0); + } +} + +static int shortcut1_edge_info_r(const struct agar_graph *gr, + const void *nr, const void *e, + struct agar_edge_info *eir) +{ + int ni = ptr2int(nr); + int index = ptr2int(e); + + switch (ni) { + case 1: + if (index == 1) { + eir->to = int2ptr(3); + eir->icost = 3; + } else { + assert(index == 2); + eir->to = int2ptr(2); + } + break; + + case 2: + assert(index == 1); + eir->to = int2ptr(3); + break; + + default: + assert(0); + } + return 0; +} + +void shortcut1_graphr_init(struct shortcut1_graphr *s1gr) +{ + agar_init_graph(&s1gr->gr, shortcut1_first_edge_r, + shortcut1_next_edge_r, + shortcut1_edge_info_r); +}