uniqgraph.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2021
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. * These are the four essential freedoms with GNU GPL software:
  18. * 1: freedom to run the program, for any purpose
  19. * 2: freedom to study how the program works, and change it to make it do what you wish
  20. * 3: freedom to redistribute copies to help your Free Software friends
  21. * 4: freedom to distribute copies of your modified versions to your Free Software friends
  22. * , ,
  23. * / \
  24. * ((__-^^-,-^^-__))
  25. * `-_---' `---_-'
  26. * `--|o` 'o|--'
  27. * \ ` /
  28. * ): :(
  29. * :o_o:
  30. * "-"
  31. *
  32. * SPDX-License-Identifier: GPL-3.0+
  33. * License-Filename: LICENSE
  34. */
  35. #include "config.h"
  36. #include <stdio.h>
  37. #include "splay-tree.h"
  38. #include "main.h"
  39. #include "uniqgraph.h"
  40. /* by uniq number of subgraph and 0 is rootgraph */
  41. static splay_tree uniqgraph_splaytree = NULL;
  42. /* */
  43. void clear_uniqgraph(struct gml_graph *g)
  44. {
  45. if (g) {
  46. }
  47. uniqgraph_splaytree = splay_tree_delete(uniqgraph_splaytree);
  48. return;
  49. }
  50. /* */
  51. void uniqgraph_add(struct gml_graph *g, int sgnum)
  52. {
  53. splay_tree_node spn = NULL;
  54. if (g == NULL) {
  55. /* shouldnothappen */
  56. return;
  57. }
  58. if (uniqgraph_splaytree == NULL) {
  59. uniqgraph_splaytree = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
  60. }
  61. spn = splay_tree_lookup(uniqgraph_splaytree, (splay_tree_key) sgnum);
  62. if (spn) {
  63. /* shouldnothappen */
  64. printf("%s(): graph does already exist\n", __func__);
  65. fflush(stdout);
  66. return;
  67. } else {
  68. splay_tree_insert(uniqgraph_splaytree, (splay_tree_key) sgnum, (splay_tree_value) g);
  69. }
  70. return;
  71. }
  72. /* */
  73. struct gml_graph *uniqgraph(int sgnum)
  74. {
  75. splay_tree_node spn = NULL;
  76. if (uniqgraph_splaytree == NULL) {
  77. uniqgraph_splaytree = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
  78. }
  79. spn = splay_tree_lookup(uniqgraph_splaytree, (splay_tree_key) sgnum);
  80. if (spn) {
  81. return ((struct gml_graph *)spn->value);
  82. } else {
  83. return (NULL);
  84. }
  85. }
  86. /* end */