source: appstream-generator/build/girepo/glib/BBTree.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 11.5 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser 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 software 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 Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module glib.BBTree;
22
23private import gi.glib;
24public  import gi.glibtypes;
25private import glib.ConstructionException;
26
27
28/**
29 * The GTree struct is an opaque data structure representing a
30 * [balanced binary tree][glib-Balanced-Binary-Trees]. It should be
31 * accessed only by using the following functions.
32 */
33public class BBTree
34{
35        /** the main Gtk struct */
36        protected GTree* gTree;
37        protected bool ownedRef;
38
39        /** Get the main Gtk struct */
40        public GTree* getBBTreeStruct()
41        {
42                return gTree;
43        }
44
45        /** the main Gtk struct as a void* */
46        protected void* getStruct()
47        {
48                return cast(void*)gTree;
49        }
50
51        /**
52         * Sets our main struct and passes it to the parent class.
53         */
54        public this (GTree* gTree, bool ownedRef = false)
55        {
56                this.gTree = gTree;
57                this.ownedRef = ownedRef;
58        }
59
60
61        /**
62         * Removes all keys and values from the #GTree and decreases its
63         * reference count by one. If keys and/or values are dynamically
64         * allocated, you should either free them first or create the #GTree
65         * using g_tree_new_full(). In the latter case the destroy functions
66         * you supplied will be called on all keys and values before destroying
67         * the #GTree.
68         */
69        public void destroy()
70        {
71                g_tree_destroy(gTree);
72        }
73
74        /**
75         * Calls the given function for each of the key/value pairs in the #GTree.
76         * The function is passed the key and value of each pair, and the given
77         * @data parameter. The tree is traversed in sorted order.
78         *
79         * The tree may not be modified while iterating over it (you can't
80         * add/remove items). To remove all items matching a predicate, you need
81         * to add each item to a list in your #GTraverseFunc as you walk over
82         * the tree, then walk the list and remove each item.
83         *
84         * Params:
85         *     func = the function to call for each node visited.
86         *         If this function returns %TRUE, the traversal is stopped.
87         *     userData = user data to pass to the function
88         */
89        public void foreac(GTraverseFunc func, void* userData)
90        {
91                g_tree_foreach(gTree, func, userData);
92        }
93
94        /**
95         * Gets the height of a #GTree.
96         *
97         * If the #GTree contains no nodes, the height is 0.
98         * If the #GTree contains only one root node the height is 1.
99         * If the root node has children the height is 2, etc.
100         *
101         * Returns: the height of @tree
102         */
103        public int height()
104        {
105                return g_tree_height(gTree);
106        }
107
108        /**
109         * Inserts a key/value pair into a #GTree.
110         *
111         * If the given key already exists in the #GTree its corresponding value
112         * is set to the new value. If you supplied a @value_destroy_func when
113         * creating the #GTree, the old value is freed using that function. If
114         * you supplied a @key_destroy_func when creating the #GTree, the passed
115         * key is freed using that function.
116         *
117         * The tree is automatically 'balanced' as new key/value pairs are added,
118         * so that the distance from the root to every leaf is as small as possible.
119         *
120         * Params:
121         *     key = the key to insert
122         *     value = the value corresponding to the key
123         */
124        public void insert(void* key, void* value)
125        {
126                g_tree_insert(gTree, key, value);
127        }
128
129        /**
130         * Gets the value corresponding to the given key. Since a #GTree is
131         * automatically balanced as key/value pairs are added, key lookup
132         * is O(log n) (where n is the number of key/value pairs in the tree).
133         *
134         * Params:
135         *     key = the key to look up
136         *
137         * Returns: the value corresponding to the key, or %NULL
138         *     if the key was not found
139         */
140        public void* lookup(void* key)
141        {
142                return g_tree_lookup(gTree, key);
143        }
144
145        /**
146         * Looks up a key in the #GTree, returning the original key and the
147         * associated value. This is useful if you need to free the memory
148         * allocated for the original key, for example before calling
149         * g_tree_remove().
150         *
151         * Params:
152         *     lookupKey = the key to look up
153         *     origKey = returns the original key
154         *     value = returns the value associated with the key
155         *
156         * Returns: %TRUE if the key was found in the #GTree
157         */
158        public bool lookupExtended(void* lookupKey, void** origKey, void** value)
159        {
160                return g_tree_lookup_extended(gTree, lookupKey, origKey, value) != 0;
161        }
162
163        /**
164         * Gets the number of nodes in a #GTree.
165         *
166         * Returns: the number of nodes in @tree
167         */
168        public int nnodes()
169        {
170                return g_tree_nnodes(gTree);
171        }
172
173        /**
174         * Increments the reference count of @tree by one.
175         *
176         * It is safe to call this function from any thread.
177         *
178         * Returns: the passed in #GTree
179         *
180         * Since: 2.22
181         */
182        public BBTree doref()
183        {
184                auto p = g_tree_ref(gTree);
185               
186                if(p is null)
187                {
188                        return null;
189                }
190               
191                return new BBTree(cast(GTree*) p);
192        }
193
194        /**
195         * Removes a key/value pair from a #GTree.
196         *
197         * If the #GTree was created using g_tree_new_full(), the key and value
198         * are freed using the supplied destroy functions, otherwise you have to
199         * make sure that any dynamically allocated values are freed yourself.
200         * If the key does not exist in the #GTree, the function does nothing.
201         *
202         * Params:
203         *     key = the key to remove
204         *
205         * Returns: %TRUE if the key was found (prior to 2.8, this function
206         *     returned nothing)
207         */
208        public bool remove(void* key)
209        {
210                return g_tree_remove(gTree, key) != 0;
211        }
212
213        /**
214         * Inserts a new key and value into a #GTree similar to g_tree_insert().
215         * The difference is that if the key already exists in the #GTree, it gets
216         * replaced by the new key. If you supplied a @value_destroy_func when
217         * creating the #GTree, the old value is freed using that function. If you
218         * supplied a @key_destroy_func when creating the #GTree, the old key is
219         * freed using that function.
220         *
221         * The tree is automatically 'balanced' as new key/value pairs are added,
222         * so that the distance from the root to every leaf is as small as possible.
223         *
224         * Params:
225         *     key = the key to insert
226         *     value = the value corresponding to the key
227         */
228        public void replace(void* key, void* value)
229        {
230                g_tree_replace(gTree, key, value);
231        }
232
233        /**
234         * Searches a #GTree using @search_func.
235         *
236         * The @search_func is called with a pointer to the key of a key/value
237         * pair in the tree, and the passed in @user_data. If @search_func returns
238         * 0 for a key/value pair, then the corresponding value is returned as
239         * the result of g_tree_search(). If @search_func returns -1, searching
240         * will proceed among the key/value pairs that have a smaller key; if
241         * @search_func returns 1, searching will proceed among the key/value
242         * pairs that have a larger key.
243         *
244         * Params:
245         *     searchFunc = a function used to search the #GTree
246         *     userData = the data passed as the second argument to @search_func
247         *
248         * Returns: the value corresponding to the found key, or %NULL
249         *     if the key was not found
250         */
251        public void* search(GCompareFunc searchFunc, void* userData)
252        {
253                return g_tree_search(gTree, searchFunc, userData);
254        }
255
256        /**
257         * Removes a key and its associated value from a #GTree without calling
258         * the key and value destroy functions.
259         *
260         * If the key does not exist in the #GTree, the function does nothing.
261         *
262         * Params:
263         *     key = the key to remove
264         *
265         * Returns: %TRUE if the key was found (prior to 2.8, this function
266         *     returned nothing)
267         */
268        public bool steal(void* key)
269        {
270                return g_tree_steal(gTree, key) != 0;
271        }
272
273        /**
274         * Calls the given function for each node in the #GTree.
275         *
276         * Deprecated: The order of a balanced tree is somewhat arbitrary.
277         * If you just want to visit all nodes in sorted order, use
278         * g_tree_foreach() instead. If you really need to visit nodes in
279         * a different order, consider using an [n-ary tree][glib-N-ary-Trees].
280         *
281         * Params:
282         *     traverseFunc = the function to call for each node visited. If this
283         *         function returns %TRUE, the traversal is stopped.
284         *     traverseType = the order in which nodes are visited, one of %G_IN_ORDER,
285         *         %G_PRE_ORDER and %G_POST_ORDER
286         *     userData = user data to pass to the function
287         */
288        public void traverse(GTraverseFunc traverseFunc, GTraverseType traverseType, void* userData)
289        {
290                g_tree_traverse(gTree, traverseFunc, traverseType, userData);
291        }
292
293        /**
294         * Decrements the reference count of @tree by one.
295         * If the reference count drops to 0, all keys and values will
296         * be destroyed (if destroy functions were specified) and all
297         * memory allocated by @tree will be released.
298         *
299         * It is safe to call this function from any thread.
300         *
301         * Since: 2.22
302         */
303        public void unref()
304        {
305                g_tree_unref(gTree);
306        }
307
308        /**
309         * Creates a new #GTree.
310         *
311         * Params:
312         *     keyCompareFunc = the function used to order the nodes in the #GTree.
313         *         It should return values similar to the standard strcmp() function -
314         *         0 if the two arguments are equal, a negative value if the first argument
315         *         comes before the second, or a positive value if the first argument comes
316         *         after the second.
317         *
318         * Returns: a newly allocated #GTree
319         *
320         * Throws: ConstructionException GTK+ fails to create the object.
321         */
322        public this(GCompareFunc keyCompareFunc)
323        {
324                auto p = g_tree_new(keyCompareFunc);
325               
326                if(p is null)
327                {
328                        throw new ConstructionException("null returned by new");
329                }
330               
331                this(cast(GTree*) p);
332        }
333
334        /**
335         * Creates a new #GTree like g_tree_new() and allows to specify functions
336         * to free the memory allocated for the key and value that get called when
337         * removing the entry from the #GTree.
338         *
339         * Params:
340         *     keyCompareFunc = qsort()-style comparison function
341         *     keyCompareData = data to pass to comparison function
342         *     keyDestroyFunc = a function to free the memory allocated for the key
343         *         used when removing the entry from the #GTree or %NULL if you don't
344         *         want to supply such a function
345         *     valueDestroyFunc = a function to free the memory allocated for the
346         *         value used when removing the entry from the #GTree or %NULL if you
347         *         don't want to supply such a function
348         *
349         * Returns: a newly allocated #GTree
350         *
351         * Throws: ConstructionException GTK+ fails to create the object.
352         */
353        public this(GCompareDataFunc keyCompareFunc, void* keyCompareData, GDestroyNotify keyDestroyFunc, GDestroyNotify valueDestroyFunc)
354        {
355                auto p = g_tree_new_full(keyCompareFunc, keyCompareData, keyDestroyFunc, valueDestroyFunc);
356               
357                if(p is null)
358                {
359                        throw new ConstructionException("null returned by new_full");
360                }
361               
362                this(cast(GTree*) p);
363        }
364
365        /**
366         * Creates a new #GTree with a comparison function that accepts user data.
367         * See g_tree_new() for more details.
368         *
369         * Params:
370         *     keyCompareFunc = qsort()-style comparison function
371         *     keyCompareData = data to pass to comparison function
372         *
373         * Returns: a newly allocated #GTree
374         *
375         * Throws: ConstructionException GTK+ fails to create the object.
376         */
377        public this(GCompareDataFunc keyCompareFunc, void* keyCompareData)
378        {
379                auto p = g_tree_new_with_data(keyCompareFunc, keyCompareData);
380               
381                if(p is null)
382                {
383                        throw new ConstructionException("null returned by new_with_data");
384                }
385               
386                this(cast(GTree*) p);
387        }
388}
Note: See TracBrowser for help on using the repository browser.