et-forest.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* Et-forest data structure implementation.
  2. Copyright (C) 2002-2015 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; see the file COPYING3. If not see
  13. <http://www.gnu.org/licenses/>. */
  14. /* This package implements ET forest data structure. Each tree in
  15. the structure maintains a tree structure and offers logarithmic time
  16. for tree operations (insertion and removal of nodes and edges) and
  17. poly-logarithmic time for nearest common ancestor.
  18. ET tree stores its structure as a sequence of symbols obtained
  19. by dfs(root)
  20. dfs (node)
  21. {
  22. s = node;
  23. for each child c of node do
  24. s = concat (s, c, node);
  25. return s;
  26. }
  27. For example for tree
  28. 1
  29. / | \
  30. 2 3 4
  31. / |
  32. 4 5
  33. the sequence is 1 2 4 2 5 3 1 3 1 4 1.
  34. The sequence is stored in a slightly modified splay tree.
  35. In order to support various types of node values, a hashtable
  36. is used to convert node values to the internal representation. */
  37. #ifndef _ET_TREE_H
  38. #define _ET_TREE_H
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif /* __cplusplus */
  42. /* The node representing the node in an et tree. */
  43. struct et_node
  44. {
  45. void *data; /* The data represented by the node. */
  46. int dfs_num_in, dfs_num_out; /* Number of the node in the dfs ordering. */
  47. struct et_node *father; /* Father of the node. */
  48. struct et_node *son; /* The first of the sons of the node. */
  49. struct et_node *left;
  50. struct et_node *right; /* The brothers of the node. */
  51. struct et_occ *rightmost_occ; /* The rightmost occurrence. */
  52. struct et_occ *parent_occ; /* The occurrence of the parent node. */
  53. };
  54. struct et_node *et_new_tree (void *data);
  55. void et_free_tree (struct et_node *);
  56. void et_free_tree_force (struct et_node *);
  57. void et_free_pools (void);
  58. void et_set_father (struct et_node *, struct et_node *);
  59. void et_split (struct et_node *);
  60. struct et_node *et_nca (struct et_node *, struct et_node *);
  61. bool et_below (struct et_node *, struct et_node *);
  62. struct et_node *et_root (struct et_node *);
  63. #ifdef __cplusplus
  64. }
  65. #endif /* __cplusplus */
  66. #endif /* _ET_TREE_H */