dpun.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "config.h"
  33. #include <stdio.h>
  34. #include "splay-tree.h"
  35. #include "main.h"
  36. #include "dp.h"
  37. #include "dpun.h"
  38. /* by uniq number of node */
  39. static splay_tree uniqnode_splaytree = NULL;
  40. void clear_dpuniqnode(void)
  41. {
  42. uniqnode_splaytree = splay_tree_delete(uniqnode_splaytree);
  43. return;
  44. }
  45. void dpuniqnode_add(struct dpnode *node)
  46. {
  47. splay_tree_node spn;
  48. if (node == NULL) {
  49. /* shouldnothappen */
  50. return;
  51. }
  52. if (uniqnode_splaytree == NULL) {
  53. uniqnode_splaytree = splay_tree_new(splay_tree_compare_strings, NULL, NULL);
  54. }
  55. spn = splay_tree_lookup(uniqnode_splaytree, (splay_tree_key) node->name);
  56. if (spn) {
  57. /* shouldnothappen */
  58. printf("dot %s(): node `%s' does already exist\n", __func__, node->name);
  59. fflush(stdout);
  60. return;
  61. } else {
  62. splay_tree_insert(uniqnode_splaytree, (splay_tree_key) node->name, (splay_tree_value) node);
  63. }
  64. return;
  65. }
  66. struct dpnode *dpuniqnode(char *name)
  67. {
  68. splay_tree_node spn;
  69. if (uniqnode_splaytree == NULL) {
  70. return (NULL);
  71. }
  72. spn = splay_tree_lookup(uniqnode_splaytree, (splay_tree_key) name);
  73. if (spn) {
  74. return ((struct dpnode *)spn->value);
  75. } else {
  76. return (NULL);
  77. }
  78. }
  79. /* end */