rawgraph.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*************************************************************************
  2. * Copyright (c) 2011 AT&T Intellectual Property
  3. * All rights reserved. This program and the accompanying materials
  4. * are made available under the terms of the Eclipse Public License v1.0
  5. * which accompanies this distribution, and is available at
  6. * https://www.eclipse.org/legal/epl-v10.html
  7. *
  8. * Contributors: Details at https://graphviz.org
  9. *************************************************************************/
  10. #pragma once
  11. #include <cgraph/list.h>
  12. #include <stdbool.h>
  13. #include <stddef.h>
  14. DEFINE_LIST(adj_list, size_t)
  15. typedef struct {
  16. int color;
  17. int topsort_order;
  18. adj_list_t adj_list; ///< adjacency list
  19. } vertex;
  20. typedef struct {
  21. size_t nvs;
  22. vertex* vertices;
  23. } rawgraph;
  24. /// makes a graph with n vertices, 0 edges
  25. rawgraph *make_graph(size_t n);
  26. extern void free_graph(rawgraph*);
  27. /// inserts edge FROM v1 to v2
  28. void insert_edge(rawgraph *, size_t v1, size_t v2);
  29. /// removes any edge between v1 to v2 -- irrespective of direction
  30. void remove_redge(rawgraph *, size_t v1, size_t v2);
  31. /// tests if there is an edge FROM v1 TO v2
  32. bool edge_exists(rawgraph *, size_t v1, size_t v2);
  33. /* topologically sorts the directed graph */
  34. extern void top_sort(rawgraph*);