vcgun.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 <zlib.h>
  38. #include "splay-tree.h"
  39. #include "main.h"
  40. #include "vcg.h"
  41. #include "vcgun.h"
  42. /* by uniq number of node */
  43. static splay_tree vcguniqnode_splaytree = NULL;
  44. void clear_vcguniqnode(void)
  45. {
  46. vcguniqnode_splaytree = splay_tree_delete(vcguniqnode_splaytree);
  47. return;
  48. }
  49. void vcguniqnode_add(struct vcgn *node)
  50. {
  51. splay_tree_node spn;
  52. if (node == NULL) {
  53. /* shouldnothappen */
  54. return;
  55. }
  56. if (vcguniqnode_splaytree == NULL) {
  57. vcguniqnode_splaytree = splay_tree_new(splay_tree_compare_strings, NULL, NULL);
  58. }
  59. spn = splay_tree_lookup(vcguniqnode_splaytree, (splay_tree_key) node->name);
  60. if (spn) {
  61. /* shouldnothappen */
  62. printf("%s(): node `%s' does already exist\n", __func__, node->name);
  63. fflush(stdout);
  64. return;
  65. } else {
  66. splay_tree_insert(vcguniqnode_splaytree, (splay_tree_key) node->name, (splay_tree_value) node);
  67. }
  68. return;
  69. }
  70. struct vcgn *vcguniqnode(char *name)
  71. {
  72. splay_tree_node spn;
  73. if (vcguniqnode_splaytree == NULL) {
  74. return (NULL);
  75. }
  76. spn = splay_tree_lookup(vcguniqnode_splaytree, (splay_tree_key) name);
  77. if (spn) {
  78. return ((struct vcgn *)spn->value);
  79. } else {
  80. return (NULL);
  81. }
  82. }
  83. /* end */