parallel.c 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #include "config.h"
  2. #include <assert.h>
  3. #include <ccan/aga/aga.h>
  4. #include <ccan/container_of/container_of.h>
  5. #include <ccan/ptrint/ptrint.h>
  6. #include "simple-graph.h"
  7. static ptrint_t *parallel_first_edge(const struct aga_graph *g,
  8. const struct aga_node *n)
  9. {
  10. struct parallel_graph *pg = container_of(g, struct parallel_graph, sg.g);
  11. if (n != &pg->sg.nodes[1]) {
  12. assert(n == &pg->sg.nodes[2]);
  13. return NULL;
  14. }
  15. if (pg->nlinks)
  16. return int2ptr(1);
  17. else
  18. return NULL;
  19. }
  20. static ptrint_t *parallel_next_edge(const struct aga_graph *g,
  21. const struct aga_node *n,
  22. ptrint_t *edge)
  23. {
  24. struct parallel_graph *pg = container_of(g, struct parallel_graph, sg.g);
  25. int index = ptr2int(edge);
  26. if (n != &pg->sg.nodes[1]) {
  27. assert(n == &pg->sg.nodes[2]);
  28. return NULL;
  29. }
  30. if (index < pg->nlinks)
  31. return int2ptr(index + 1);
  32. else
  33. return NULL;
  34. }
  35. static int parallel_edge_info(const struct aga_graph *g, const struct aga_node *n,
  36. ptrint_t *edge, struct aga_edge_info *ei)
  37. {
  38. struct parallel_graph *pg = container_of(g, struct parallel_graph, sg.g);
  39. assert(n == &pg->sg.nodes[1]);
  40. ei->to = &pg->sg.nodes[2];
  41. return 0;
  42. }
  43. void parallel_graph_init(struct parallel_graph *pg, int nlinks)
  44. {
  45. pg->nlinks = nlinks;
  46. simple_graph_init(&pg->sg, parallel_first_edge, parallel_next_edge,
  47. parallel_edge_info);
  48. }