graph.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* This file is part of nit.
  2. *
  3. * Nit is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU Lesser General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * Nit is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Lesser General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Lesser General Public License
  14. * along with nit. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef GRAPH_H
  17. #define GRAPH_H
  18. #include "set.h"
  19. typedef struct Graph_node {
  20. void *vertex;
  21. Set edges; /* Treated as map if named edges */
  22. } Graph_node;
  23. typedef struct Graph {
  24. Disposer nd_dspr;
  25. Set nodes;
  26. } Graph;
  27. /* set map to nonzero for named edges */
  28. Nit_error
  29. graph_init(Graph *graph, Disposer *vrtx_dspr, int map);
  30. void
  31. graph_dispose(Graph *graph);
  32. Graph_node *
  33. graph_node(Graph *graph, void *vertex);
  34. void *
  35. graph_denode(Graph *graph, Graph_node *node, int ret_ver);
  36. /* set key to NULL if not using named edges */
  37. Nit_error
  38. graph_join(Graph_node *from, Graph_node *to,
  39. uint32_t key_len, const void *key);
  40. void
  41. graph_disjoin(Graph_node *from, Graph_node *to,
  42. uint32_t key_len, const void *key);
  43. /* should only work for named edges */
  44. Graph_node *
  45. graph_get(Graph_node *node, uint32_t key_len, const void *key);
  46. int
  47. graph_linked(Graph_node *from, Graph_node *to, Set_key *map_key);
  48. #endif