gnode.inc 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. {*
  2. * gnode.inc
  3. *
  4. * depends on gmem.inc
  5. *}
  6. type
  7. PGNode = ^TGNode;
  8. TGNode = record
  9. data : gpointer;
  10. next : PGNode;
  11. prev : PGNode;
  12. parent : PGNode;
  13. children : PGNode;
  14. end;
  15. { Tree traverse flags }
  16. PGTraverseFlags = ^TGTraverseFlags;
  17. TGTraverseFlags = gint;
  18. const
  19. G_TRAVERSE_LEAFS = 1 shl 0;
  20. G_TRAVERSE_NON_LEAFS = 1 shl 1;
  21. G_TRAVERSE_ALL = G_TRAVERSE_LEAFS or G_TRAVERSE_NON_LEAFS;
  22. G_TRAVERSE_MASK = $03;
  23. { Tree traverse orders }
  24. type
  25. PGTraverseType = ^TGTraverseType;
  26. TGTraverseType = (G_IN_ORDER,
  27. G_PRE_ORDER,
  28. G_POST_ORDER,
  29. G_LEVEL_ORDER);
  30. TGNodeTraverseFunc = function (node:PGNode; data:gpointer):gboolean;cdecl;
  31. TGNodeForeachFunc = procedure (node:PGNode; data:gpointer);cdecl;
  32. { N-way tree implementation
  33. }
  34. function G_NODE_IS_ROOT (node: PGNode): boolean;
  35. function G_NODE_IS_LEAF (node: PGNode): boolean;
  36. procedure g_node_push_allocator(allocator:PGAllocator);cdecl;external gliblib name 'g_node_push_allocator';
  37. procedure g_node_pop_allocator;cdecl;external gliblib name 'g_node_pop_allocator';
  38. function g_node_new(data:gpointer):PGNode;cdecl;external gliblib name 'g_node_new';
  39. procedure g_node_destroy(root:PGNode);cdecl;external gliblib name 'g_node_destroy';
  40. procedure g_node_unlink(node:PGNode);cdecl;external gliblib name 'g_node_unlink';
  41. function g_node_copy(node:PGNode):PGNode;cdecl;external gliblib name 'g_node_copy';
  42. function g_node_insert(parent:PGNode; position:gint; node:PGNode):PGNode;cdecl;external gliblib name 'g_node_insert';
  43. function g_node_insert_before(parent:PGNode; sibling:PGNode; node:PGNode):PGNode;cdecl;external gliblib name 'g_node_insert_before';
  44. function g_node_insert_after(parent:PGNode; sibling:PGNode; node:PGNode):PGNode;cdecl;external gliblib name 'g_node_insert_after';
  45. function g_node_prepend(parent:PGNode; node:PGNode):PGNode;cdecl;external gliblib name 'g_node_prepend';
  46. function g_node_n_nodes(root:PGNode; flags:TGTraverseFlags):guint;cdecl;external gliblib name 'g_node_n_nodes';
  47. function g_node_get_root(node:PGNode):PGNode;cdecl;external gliblib name 'g_node_get_root';
  48. function g_node_is_ancestor(node:PGNode; descendant:PGNode):gboolean;cdecl;external gliblib name 'g_node_is_ancestor';
  49. function g_node_depth(node:PGNode):guint;cdecl;external gliblib name 'g_node_depth';
  50. function g_node_find(root:PGNode; order:TGTraverseType; flags:TGTraverseFlags; data:gpointer):PGNode;cdecl;external gliblib name 'g_node_find';
  51. { convenience macros }
  52. function g_node_append (parent: PGNode; node: PGNode): PGNode;
  53. function g_node_insert_data (parent: PGNode; position: gint; data: gpointer): PGNode;
  54. function g_node_insert_data_before (parent: PGNode; sibling: PGNode; data: gpointer): PGNode;
  55. function g_node_prepend_data (parent: PGNode; data: gpointer): PGNode;
  56. function g_node_append_data (parent: PGNode; data: gpointer): PGNode;
  57. { traversal function, assumes that `node' is root
  58. (only traverses `node' and its subtree).
  59. this function is just a high level interface to
  60. low level traversal functions, optimized for speed.
  61. }
  62. function g_node_traverse (root : PGNode;
  63. order : TGTraverseType;
  64. flags : TGTraverseFlags;
  65. max_depth : gint;
  66. func : TGNodeTraverseFunc;
  67. data : gpointer):guint;cdecl;external gliblib name 'g_node_traverse';
  68. { return the maximum tree height starting with `node', this is an expensive
  69. operation, since we need to visit all nodes. this could be shortened by
  70. adding `guint height' to struct _GNode, but then again, this is not very
  71. often needed, and would make g_node_insert() more time consuming.
  72. }
  73. function g_node_max_height(root:PGNode):guint;cdecl;external gliblib name 'g_node_max_height';
  74. procedure g_node_children_foreach(node:PGNode; flags:TGTraverseFlags; func:TGNodeForeachFunc; data:gpointer);cdecl;external gliblib name 'g_node_children_foreach';
  75. procedure g_node_reverse_children(node:PGNode);cdecl;external gliblib name 'g_node_reverse_children';
  76. function g_node_n_children(node:PGNode):guint;cdecl;external gliblib name 'g_node_n_children';
  77. function g_node_nth_child(node:PGNode; n:guint):PGNode;cdecl;external gliblib name 'g_node_nth_child';
  78. function g_node_last_child(node:PGNode):PGNode;cdecl;external gliblib name 'g_node_last_child';
  79. function g_node_find_child(node:PGNode; flags:TGTraverseFlags; data:gpointer):PGNode;cdecl;external gliblib name 'g_node_find_child';
  80. function g_node_child_position(node:PGNode; child:PGNode):gint;cdecl;external gliblib name 'g_node_child_position';
  81. function g_node_child_index(node:PGNode; data:gpointer):gint;cdecl;external gliblib name 'g_node_child_index';
  82. function g_node_first_sibling(node:PGNode):PGNode;cdecl;external gliblib name 'g_node_first_sibling';
  83. function g_node_last_sibling(node:PGNode):PGNode;cdecl;external gliblib name 'g_node_last_sibling';
  84. function g_node_prev_sibling (node : PGNode): PGNode;
  85. function g_node_next_sibling (node : PGNode): PGNode;
  86. function g_node_first_child (node : PGNode): PGNode;