2.7.0
[glib.git] / docs / reference / glib / tmpl / trees-binary.sgml
blob6d36ad72a76c39fea18287353f81eb49330f6f4d
1 <!-- ##### SECTION Title ##### -->
2 Balanced Binary Trees
4 <!-- ##### SECTION Short_Description ##### -->
5 a sorted collection of key/value pairs optimized for searching
6 and traversing in order.
8 <!-- ##### SECTION Long_Description ##### -->
9 <para>
10 The #GTree structure and its associated functions provide a sorted collection
11 of key/value pairs optimized for searching and traversing in order.
12 </para>
13 <para>
14 To create a new #GTree use g_tree_new().
15 </para>
16 <para>
17 To insert a key/value pair into a #GTree use g_tree_insert().
18 </para>
19 <para>
20 To lookup the value corresponding to a given key, use g_tree_lookup() and
21 g_tree_lookup_extended().
22 </para>
23 <para>
24 To find out the number of nodes in a #GTree, use g_tree_nnodes().
25 To get the height of a #GTree, use g_tree_height().
26 </para>
27 <para>
28 To traverse a #GTree, calling a function for each node visited in the
29 traversal, use g_tree_foreach().
30 </para>
31 <para>
32 To remove a key/value pair use g_tree_remove().
33 </para>
34 <para>
35 To destroy a #GTree, use g_tree_destroy().
36 </para>
38 <!-- ##### SECTION See_Also ##### -->
39 <para>
41 </para>
43 <!-- ##### SECTION Stability_Level ##### -->
46 <!-- ##### STRUCT GTree ##### -->
47 <para>
48 The <structname>GTree</structname> struct is an opaque data structure representing a
49 <link linkend="glib-Balanced-Binary-Trees">Balanced Binary Tree</link>.
50 It should be accessed only by using the following functions.
51 </para>
54 <!-- ##### FUNCTION g_tree_new ##### -->
55 <para>
57 </para>
59 @key_compare_func:
60 @Returns:
63 <!-- ##### FUNCTION g_tree_new_with_data ##### -->
64 <para>
66 </para>
68 @key_compare_func:
69 @key_compare_data:
70 @Returns:
73 <!-- ##### FUNCTION g_tree_new_full ##### -->
74 <para>
76 </para>
78 @key_compare_func:
79 @key_compare_data:
80 @key_destroy_func:
81 @value_destroy_func:
82 @Returns:
85 <!-- ##### FUNCTION g_tree_insert ##### -->
86 <para>
88 </para>
90 @tree:
91 @key:
92 @value:
95 <!-- ##### FUNCTION g_tree_replace ##### -->
96 <para>
98 </para>
100 @tree:
101 @key:
102 @value:
105 <!-- ##### FUNCTION g_tree_nnodes ##### -->
106 <para>
108 </para>
110 @tree:
111 @Returns:
114 <!-- ##### FUNCTION g_tree_height ##### -->
115 <para>
117 </para>
119 @tree:
120 @Returns:
123 <!-- ##### FUNCTION g_tree_lookup ##### -->
124 <para>
126 </para>
128 @tree:
129 @key:
130 @Returns:
133 <!-- ##### FUNCTION g_tree_lookup_extended ##### -->
136 @tree:
137 @lookup_key:
138 @orig_key:
139 @value:
140 @Returns:
143 <!-- ##### FUNCTION g_tree_foreach ##### -->
144 <para>
146 </para>
148 @tree:
149 @func:
150 @user_data:
153 <!-- ##### FUNCTION g_tree_traverse ##### -->
154 <para>
156 </para>
158 @tree:
159 @traverse_func:
160 @traverse_type:
161 @user_data:
164 <!-- ##### USER_FUNCTION GTraverseFunc ##### -->
165 <para>
166 Specifies the type of function passed to g_tree_traverse().
167 It is passed the key and value of each node, together with
168 the @user_data parameter passed to g_tree_traverse().
169 If the function returns %TRUE, the traversal is stopped.
170 </para>
172 @key: a key of a #GTree node.
173 @value: the value corresponding to the key.
174 @data: user data passed to g_tree_traverse().
175 @Returns: %TRUE to stop the traversal.
178 <!-- ##### ENUM GTraverseType ##### -->
179 <para>
180 Specifies the type of traveral performed by g_tree_traverse(),
181 g_node_traverse() and g_node_find().
182 </para>
184 @G_IN_ORDER: vists a node's left child first, then the node itself, then its
185 right child. This is the one to use if you want the output sorted according
186 to the compare function.
187 @G_PRE_ORDER: visits a node, then its children.
188 @G_POST_ORDER: visits the node's children, then the node itself.
189 @G_LEVEL_ORDER: is not implemented for
190 <link linkend="glib-Balanced-Binary-Trees">Balanced Binary Trees</link>.
191 For <link linkend="glib-N-ary-Trees">N-ary Trees</link>, it vists the root
192 node first, then its children, then its grandchildren, and so on. Note that
193 this is less efficient than the other orders.
195 <!-- ##### FUNCTION g_tree_search ##### -->
196 <para>
198 </para>
200 @tree:
201 @search_func:
202 @user_data:
203 @Returns:
206 <!-- ##### FUNCTION g_tree_remove ##### -->
207 <para>
209 </para>
211 @tree:
212 @key:
213 @Returns:
216 <!-- ##### FUNCTION g_tree_steal ##### -->
217 <para>
219 </para>
221 @tree:
222 @key:
223 @Returns:
226 <!-- ##### FUNCTION g_tree_destroy ##### -->
227 <para>
229 </para>
231 @tree: