1/* GLIB - Library of useful routines for C programming
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library 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 GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18/*
19 * Modified by the GLib Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GLib Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GLib at ftp://ftp.gtk.org/pub/gtk/.
23 */
24
25#ifndef __G_TREE_H__
26#define __G_TREE_H__
27
28#if !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
29#error "Only <glib.h> can be included directly."
30#endif
31
32#include <glib/gnode.h>
33
34G_BEGIN_DECLS
35
36#undef G_TREE_DEBUG
37
38typedef struct _GTree GTree;
39
40/**
41 * GTreeNode:
42 *
43 * An opaque type which identifies a specific node in a #GTree.
44 *
45 * Since: 2.68
46 */
47typedef struct _GTreeNode GTreeNode;
48
49typedef gboolean (*GTraverseFunc) (gpointer key,
50 gpointer value,
51 gpointer data);
52
53/**
54 * GTraverseNodeFunc:
55 * @node: a #GTreeNode
56 * @data: user data passed to g_tree_foreach_node()
57 *
58 * Specifies the type of function passed to g_tree_foreach_node(). It is
59 * passed each node, together with the @user_data parameter passed to
60 * g_tree_foreach_node(). If the function returns %TRUE, the traversal is
61 * stopped.
62 *
63 * Returns: %TRUE to stop the traversal
64 * Since: 2.68
65 */
66typedef gboolean (*GTraverseNodeFunc) (GTreeNode *node,
67 gpointer data);
68
69/* Balanced binary trees
70 */
71GLIB_AVAILABLE_IN_ALL
72GTree* g_tree_new (GCompareFunc key_compare_func);
73GLIB_AVAILABLE_IN_ALL
74GTree* g_tree_new_with_data (GCompareDataFunc key_compare_func,
75 gpointer key_compare_data);
76GLIB_AVAILABLE_IN_ALL
77GTree* g_tree_new_full (GCompareDataFunc key_compare_func,
78 gpointer key_compare_data,
79 GDestroyNotify key_destroy_func,
80 GDestroyNotify value_destroy_func);
81GLIB_AVAILABLE_IN_2_68
82GTreeNode *g_tree_node_first (GTree *tree);
83GLIB_AVAILABLE_IN_2_68
84GTreeNode *g_tree_node_last (GTree *tree);
85GLIB_AVAILABLE_IN_2_68
86GTreeNode *g_tree_node_previous (GTreeNode *node);
87GLIB_AVAILABLE_IN_2_68
88GTreeNode *g_tree_node_next (GTreeNode *node);
89GLIB_AVAILABLE_IN_ALL
90GTree* g_tree_ref (GTree *tree);
91GLIB_AVAILABLE_IN_ALL
92void g_tree_unref (GTree *tree);
93GLIB_AVAILABLE_IN_ALL
94void g_tree_destroy (GTree *tree);
95GLIB_AVAILABLE_IN_2_68
96GTreeNode *g_tree_insert_node (GTree *tree,
97 gpointer key,
98 gpointer value);
99GLIB_AVAILABLE_IN_ALL
100void g_tree_insert (GTree *tree,
101 gpointer key,
102 gpointer value);
103GLIB_AVAILABLE_IN_2_68
104GTreeNode *g_tree_replace_node (GTree *tree,
105 gpointer key,
106 gpointer value);
107GLIB_AVAILABLE_IN_ALL
108void g_tree_replace (GTree *tree,
109 gpointer key,
110 gpointer value);
111GLIB_AVAILABLE_IN_ALL
112gboolean g_tree_remove (GTree *tree,
113 gconstpointer key);
114
115GLIB_AVAILABLE_IN_2_70
116void g_tree_remove_all (GTree *tree);
117
118GLIB_AVAILABLE_IN_ALL
119gboolean g_tree_steal (GTree *tree,
120 gconstpointer key);
121GLIB_AVAILABLE_IN_2_68
122gpointer g_tree_node_key (GTreeNode *node);
123GLIB_AVAILABLE_IN_2_68
124gpointer g_tree_node_value (GTreeNode *node);
125GLIB_AVAILABLE_IN_2_68
126GTreeNode *g_tree_lookup_node (GTree *tree,
127 gconstpointer key);
128GLIB_AVAILABLE_IN_ALL
129gpointer g_tree_lookup (GTree *tree,
130 gconstpointer key);
131GLIB_AVAILABLE_IN_ALL
132gboolean g_tree_lookup_extended (GTree *tree,
133 gconstpointer lookup_key,
134 gpointer *orig_key,
135 gpointer *value);
136GLIB_AVAILABLE_IN_ALL
137void g_tree_foreach (GTree *tree,
138 GTraverseFunc func,
139 gpointer user_data);
140GLIB_AVAILABLE_IN_2_68
141void g_tree_foreach_node (GTree *tree,
142 GTraverseNodeFunc func,
143 gpointer user_data);
144
145GLIB_DEPRECATED
146void g_tree_traverse (GTree *tree,
147 GTraverseFunc traverse_func,
148 GTraverseType traverse_type,
149 gpointer user_data);
150
151GLIB_AVAILABLE_IN_2_68
152GTreeNode *g_tree_search_node (GTree *tree,
153 GCompareFunc search_func,
154 gconstpointer user_data);
155GLIB_AVAILABLE_IN_ALL
156gpointer g_tree_search (GTree *tree,
157 GCompareFunc search_func,
158 gconstpointer user_data);
159GLIB_AVAILABLE_IN_2_68
160GTreeNode *g_tree_lower_bound (GTree *tree,
161 gconstpointer key);
162GLIB_AVAILABLE_IN_2_68
163GTreeNode *g_tree_upper_bound (GTree *tree,
164 gconstpointer key);
165GLIB_AVAILABLE_IN_ALL
166gint g_tree_height (GTree *tree);
167GLIB_AVAILABLE_IN_ALL
168gint g_tree_nnodes (GTree *tree);
169
170#ifdef G_TREE_DEBUG
171/*< private >*/
172#ifndef __GTK_DOC_IGNORE__
173void g_tree_dump (GTree *tree);
174#endif /* !__GTK_DOC_IGNORE__ */
175#endif /* G_TREE_DEBUG */
176
177G_END_DECLS
178
179#endif /* __G_TREE_H__ */
180

source code of include/glib-2.0/glib/gtree.h