uniqnode.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. * node database
  32. * uniqnode() is used for raw node data
  33. * uniqnode2() is used for work node data in nodelist
  34. * uniqnode() is indexed on node number and node id for gml graph data
  35. *
  36. * SPDX-License-Identifier: GPL-3.0+
  37. * License-Filename: LICENSE
  38. */
  39. #include "config.h"
  40. #include <stdio.h>
  41. #include "splay-tree.h"
  42. #include "main.h"
  43. #include "uniqnode.h"
  44. /* by uniq number of node */
  45. static splay_tree uniqnode_splaytree = NULL;
  46. /* by uniq number of node */
  47. static splay_tree uniqnode_splaytree2 = NULL;
  48. /* by id number of node */
  49. static splay_tree uniqnodeid_splaytree = NULL;
  50. /* */
  51. void clear_uniqnode(struct gml_graph *g)
  52. {
  53. if (g) {
  54. }
  55. uniqnode_splaytree = splay_tree_delete(uniqnode_splaytree);
  56. uniqnodeid_splaytree = splay_tree_delete(uniqnodeid_splaytree);
  57. return;
  58. }
  59. /* */
  60. void clear_uniqnode2(struct gml_graph *g)
  61. {
  62. if (g) {
  63. }
  64. uniqnode_splaytree2 = splay_tree_delete(uniqnode_splaytree2);
  65. return;
  66. }
  67. /* */
  68. void uniqnode_add(struct gml_graph *g, struct gml_node *node)
  69. {
  70. splay_tree_node spn = NULL;
  71. if (g) {
  72. }
  73. if (node == NULL) {
  74. /* shouldnothappen */
  75. return;
  76. }
  77. if (uniqnode_splaytree == NULL) {
  78. uniqnode_splaytree = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
  79. }
  80. if (uniqnodeid_splaytree == NULL) {
  81. uniqnodeid_splaytree = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
  82. }
  83. spn = splay_tree_lookup(uniqnode_splaytree, (splay_tree_key) node->nr);
  84. if (spn) {
  85. /* shouldnothappen */
  86. printf("uniqnode_add(): node does already exist\n");
  87. fflush(stdout);
  88. return;
  89. } else {
  90. splay_tree_insert(uniqnode_splaytree, (splay_tree_key) node->nr, (splay_tree_value) node);
  91. splay_tree_insert(uniqnodeid_splaytree, (splay_tree_key) node->id, (splay_tree_value) node);
  92. }
  93. return;
  94. }
  95. /* */
  96. void uniqnode_add2(struct gml_graph *g, struct gml_node *node)
  97. {
  98. splay_tree_node spn = NULL;
  99. if (g) {
  100. }
  101. if (node == NULL) {
  102. /* shouldnothappen */
  103. return;
  104. }
  105. if (uniqnode_splaytree2 == NULL) {
  106. uniqnode_splaytree2 = splay_tree_new(splay_tree_compare_ints, NULL, NULL);
  107. }
  108. spn = splay_tree_lookup(uniqnode_splaytree2, (splay_tree_key) node->nr);
  109. if (spn) {
  110. /* shouldnothappen */
  111. printf("uniqnode_add2(): node does already exist\n");
  112. fflush(stdout);
  113. return;
  114. } else {
  115. splay_tree_insert(uniqnode_splaytree2, (splay_tree_key) node->nr, (splay_tree_value) node);
  116. }
  117. return;
  118. }
  119. /* */
  120. struct gml_node *uniqnode(struct gml_graph *g, int nr)
  121. {
  122. splay_tree_node spn = NULL;
  123. if (g) {
  124. }
  125. if (uniqnode_splaytree == NULL) {
  126. return (NULL);
  127. }
  128. spn = splay_tree_lookup(uniqnode_splaytree, (splay_tree_key) nr);
  129. if (spn) {
  130. return ((struct gml_node *)spn->value);
  131. } else {
  132. return (NULL);
  133. }
  134. }
  135. /* */
  136. struct gml_node *uniqnode2(struct gml_graph *g, int nr)
  137. {
  138. splay_tree_node spn = NULL;
  139. if (g) {
  140. }
  141. if (uniqnode_splaytree2 == NULL) {
  142. return (NULL);
  143. }
  144. spn = splay_tree_lookup(uniqnode_splaytree2, (splay_tree_key) nr);
  145. if (spn) {
  146. return ((struct gml_node *)spn->value);
  147. } else {
  148. return (NULL);
  149. }
  150. }
  151. /* */
  152. struct gml_node *uniqnodeid(struct gml_graph *g, int nr)
  153. {
  154. splay_tree_node spn = NULL;
  155. if (g) {
  156. }
  157. if (uniqnodeid_splaytree == NULL) {
  158. return (NULL);
  159. }
  160. spn = splay_tree_lookup(uniqnodeid_splaytree, (splay_tree_key) nr);
  161. if (spn) {
  162. return ((struct gml_node *)spn->value);
  163. } else {
  164. return (NULL);
  165. }
  166. }
  167. /* end */