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 34 G_BEGIN_DECLS 35 36 #undef G_TREE_DEBUG 37 38 typedef 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 */ 47 typedef struct _GTreeNode GTreeNode; 48 49 typedef 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 */ 66 typedef gboolean (*GTraverseNodeFunc) (GTreeNode *node, 67 gpointer data); 68 69 /* Balanced binary trees 70 */ 71 GLIB_AVAILABLE_IN_ALL 72 GTree* g_tree_new (GCompareFunc key_compare_func); 73 GLIB_AVAILABLE_IN_ALL 74 GTree* g_tree_new_with_data (GCompareDataFunc key_compare_func, 75 gpointer key_compare_data); 76 GLIB_AVAILABLE_IN_ALL 77 GTree* g_tree_new_full (GCompareDataFunc key_compare_func, 78 gpointer key_compare_data, 79 GDestroyNotify key_destroy_func, 80 GDestroyNotify value_destroy_func); 81 GLIB_AVAILABLE_IN_2_68 82 GTreeNode *g_tree_node_first (GTree *tree); 83 GLIB_AVAILABLE_IN_2_68 84 GTreeNode *g_tree_node_last (GTree *tree); 85 GLIB_AVAILABLE_IN_2_68 86 GTreeNode *g_tree_node_previous (GTreeNode *node); 87 GLIB_AVAILABLE_IN_2_68 88 GTreeNode *g_tree_node_next (GTreeNode *node); 89 GLIB_AVAILABLE_IN_ALL 90 GTree* g_tree_ref (GTree *tree); 91 GLIB_AVAILABLE_IN_ALL 92 void g_tree_unref (GTree *tree); 93 GLIB_AVAILABLE_IN_ALL 94 void g_tree_destroy (GTree *tree); 95 GLIB_AVAILABLE_IN_2_68 96 GTreeNode *g_tree_insert_node (GTree *tree, 97 gpointer key, 98 gpointer value); 99 GLIB_AVAILABLE_IN_ALL 100 void g_tree_insert (GTree *tree, 101 gpointer key, 102 gpointer value); 103 GLIB_AVAILABLE_IN_2_68 104 GTreeNode *g_tree_replace_node (GTree *tree, 105 gpointer key, 106 gpointer value); 107 GLIB_AVAILABLE_IN_ALL 108 void g_tree_replace (GTree *tree, 109 gpointer key, 110 gpointer value); 111 GLIB_AVAILABLE_IN_ALL 112 gboolean g_tree_remove (GTree *tree, 113 gconstpointer key); 114 GLIB_AVAILABLE_IN_ALL 115 gboolean g_tree_steal (GTree *tree, 116 gconstpointer key); 117 GLIB_AVAILABLE_IN_2_68 118 gpointer g_tree_node_key (GTreeNode *node); 119 GLIB_AVAILABLE_IN_2_68 120 gpointer g_tree_node_value (GTreeNode *node); 121 GLIB_AVAILABLE_IN_2_68 122 GTreeNode *g_tree_lookup_node (GTree *tree, 123 gconstpointer key); 124 GLIB_AVAILABLE_IN_ALL 125 gpointer g_tree_lookup (GTree *tree, 126 gconstpointer key); 127 GLIB_AVAILABLE_IN_ALL 128 gboolean g_tree_lookup_extended (GTree *tree, 129 gconstpointer lookup_key, 130 gpointer *orig_key, 131 gpointer *value); 132 GLIB_AVAILABLE_IN_ALL 133 void g_tree_foreach (GTree *tree, 134 GTraverseFunc func, 135 gpointer user_data); 136 GLIB_AVAILABLE_IN_2_68 137 void g_tree_foreach_node (GTree *tree, 138 GTraverseNodeFunc func, 139 gpointer user_data); 140 141 GLIB_DEPRECATED 142 void g_tree_traverse (GTree *tree, 143 GTraverseFunc traverse_func, 144 GTraverseType traverse_type, 145 gpointer user_data); 146 147 GLIB_AVAILABLE_IN_2_68 148 GTreeNode *g_tree_search_node (GTree *tree, 149 GCompareFunc search_func, 150 gconstpointer user_data); 151 GLIB_AVAILABLE_IN_ALL 152 gpointer g_tree_search (GTree *tree, 153 GCompareFunc search_func, 154 gconstpointer user_data); 155 GLIB_AVAILABLE_IN_2_68 156 GTreeNode *g_tree_lower_bound (GTree *tree, 157 gconstpointer key); 158 GLIB_AVAILABLE_IN_2_68 159 GTreeNode *g_tree_upper_bound (GTree *tree, 160 gconstpointer key); 161 GLIB_AVAILABLE_IN_ALL 162 gint g_tree_height (GTree *tree); 163 GLIB_AVAILABLE_IN_ALL 164 gint g_tree_nnodes (GTree *tree); 165 166 #ifdef G_TREE_DEBUG 167 /*< private >*/ 168 #ifndef __GTK_DOC_IGNORE__ 169 void g_tree_dump (GTree *tree); 170 #endif /* !__GTK_DOC_IGNORE__ */ 171 #endif /* G_TREE_DEBUG */ 172 173 G_END_DECLS 174 175 #endif /* __G_TREE_H__ */ 176