X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Faga%2Ftest%2Fshortcut2.c;fp=ccan%2Faga%2Ftest%2Fshortcut2.c;h=33eee0a941daf3d1e4ce92497d756148bff37e70;hb=09378088f7f49f30cb61435712a8dc2e52a32f69;hp=0000000000000000000000000000000000000000;hpb=13430d4e252edbe0c202237e5a956670da1efe0b;p=ccan diff --git a/ccan/aga/test/shortcut2.c b/ccan/aga/test/shortcut2.c new file mode 100644 index 00000000..33eee0a9 --- /dev/null +++ b/ccan/aga/test/shortcut2.c @@ -0,0 +1,94 @@ +#include "config.h" + +#include + +#include +#include + +#include + +#include "simple-graph.h" + +static ptrint_t *shortcut2_first_edge(const struct aga_graph *g, + const struct aga_node *n) +{ + struct shortcut2_graph *s1g = container_of(g, struct shortcut2_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 *shortcut2_next_edge(const struct aga_graph *g, + const struct aga_node *n, + ptrint_t *e) +{ + struct shortcut2_graph *s1g = container_of(g, struct shortcut2_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 shortcut2_edge_info(const struct aga_graph *g, + const struct aga_node *n, + ptrint_t *e, struct aga_edge_info *ei) +{ + struct shortcut2_graph *s1g = container_of(g, struct shortcut2_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]; + } else { + assert(index == 2); + ei->to = &s1g->sg.nodes[2]; + } + ei->icost = 2; + break; + + case 2: + assert(index == 1); + ei->to = &s1g->sg.nodes[3]; + ei->icost = -1; + break; + + default: + assert(0); + } + return 0; +} + +void shortcut2_graph_init(struct shortcut2_graph *s1g) +{ + simple_graph_init(&s1g->sg, shortcut2_first_edge, + shortcut2_next_edge, + shortcut2_edge_info); +}