X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Faga%2Ftest%2Fshortcut1.c;fp=ccan%2Faga%2Ftest%2Fshortcut1.c;h=bea05a64ceab01178d8a730f851013bf458c0879;hb=13430d4e252edbe0c202237e5a956670da1efe0b;hp=0000000000000000000000000000000000000000;hpb=a2eaae42b58a44d6f88f5e20e4a7d7cdbde9edae;p=ccan diff --git a/ccan/aga/test/shortcut1.c b/ccan/aga/test/shortcut1.c new file mode 100644 index 00000000..bea05a64 --- /dev/null +++ b/ccan/aga/test/shortcut1.c @@ -0,0 +1,93 @@ +#include "config.h" + +#include + +#include +#include + +#include + +#include "simple-graph.h" + +static ptrint_t *shortcut1_first_edge(const struct aga_graph *g, + const struct aga_node *n) +{ + struct shortcut1_graph *s1g = container_of(g, struct shortcut1_graph, + sg.g); + int ni = n - s1g->sg.nodes; + + switch (ni) { + case 1: + case 2: + return int2ptr(1); + + case 3: + return NULL; + + default: + assert(0); + } +} + +static ptrint_t *shortcut1_next_edge(const struct aga_graph *g, + const struct aga_node *n, + ptrint_t *e) +{ + struct shortcut1_graph *s1g = container_of(g, struct shortcut1_graph, + sg.g); + int ni = n - s1g->sg.nodes; + 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(const struct aga_graph *g, + const struct aga_node *n, + ptrint_t *e, struct aga_edge_info *ei) +{ + struct shortcut1_graph *s1g = container_of(g, struct shortcut1_graph, + sg.g); + int ni = n - s1g->sg.nodes; + int index = ptr2int(e); + + switch (ni) { + case 1: + if (index == 1) { + ei->to = &s1g->sg.nodes[3]; + ei->icost = 3; + } else { + assert(index == 2); + ei->to = &s1g->sg.nodes[2]; + } + break; + + case 2: + assert(index == 1); + ei->to = &s1g->sg.nodes[3]; + break; + + default: + assert(0); + } + return 0; +} + +void shortcut1_graph_init(struct shortcut1_graph *s1g) +{ + simple_graph_init(&s1g->sg, shortcut1_first_edge, + shortcut1_next_edge, + shortcut1_edge_info); +}