X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Faga%2Ftest%2Fparallel.c;fp=ccan%2Faga%2Ftest%2Fparallel.c;h=997280bc24ec964b57c2fdaf3ed674d13f5a9969;hb=2192bdd98afbb1ddb489c863edd191877051de8b;hp=0000000000000000000000000000000000000000;hpb=3b7409ea08a7d1643bc7de31ece63e20b89f319b;p=ccan diff --git a/ccan/aga/test/parallel.c b/ccan/aga/test/parallel.c new file mode 100644 index 00000000..997280bc --- /dev/null +++ b/ccan/aga/test/parallel.c @@ -0,0 +1,62 @@ +#include "config.h" + +#include + +#include +#include +#include + +#include "simple-graph.h" + +static ptrint_t *parallel_first_edge(const struct aga_graph *g, + const struct aga_node *n) +{ + struct parallel_graph *pg = container_of(g, struct parallel_graph, sg.g); + + if (n != &pg->sg.nodes[1]) { + assert(n == &pg->sg.nodes[2]); + return NULL; + } + + if (pg->nlinks) + return int2ptr(1); + else + return NULL; +} + +static ptrint_t *parallel_next_edge(const struct aga_graph *g, + const struct aga_node *n, + ptrint_t *edge) +{ + struct parallel_graph *pg = container_of(g, struct parallel_graph, sg.g); + int index = ptr2int(edge); + + if (n != &pg->sg.nodes[1]) { + assert(n == &pg->sg.nodes[2]); + return NULL; + } + + if (index < pg->nlinks) + return int2ptr(index + 1); + else + return NULL; +} + +static int parallel_edge_info(const struct aga_graph *g, const struct aga_node *n, + ptrint_t *edge, struct aga_edge_info *ei) +{ + struct parallel_graph *pg = container_of(g, struct parallel_graph, sg.g); + + assert(n == &pg->sg.nodes[1]); + + ei->to = &pg->sg.nodes[2]; + return 0; +} + +void parallel_graph_init(struct parallel_graph *pg, int nlinks) +{ + pg->nlinks = nlinks; + + simple_graph_init(&pg->sg, parallel_first_edge, parallel_next_edge, + parallel_edge_info); +}