MOON
Server: Apache/2.2.31 (Unix) mod_ssl/2.2.31 OpenSSL/0.9.8e-fips-rhel5 mod_bwlimited/1.4
System: Linux csr818.wilogic.com 2.6.18-419.el5xen #1 SMP Fri Feb 24 22:50:37 UTC 2017 x86_64
User: digitals (531)
PHP: 5.4.45
Disabled: NONE
Upload Files
File: //usr/share/gtk-doc/html/glib/glib-Balanced-Binary-Trees.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Balanced Binary Trees</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.69.1">
<link rel="start" href="index.html" title="GLib Reference Manual">
<link rel="up" href="glib-data-types.html" title="GLib Data Types">
<link rel="prev" href="glib-Byte-Arrays.html" title="Byte Arrays">
<link rel="next" href="glib-N-ary-Trees.html" title="N-ary Trees">
<meta name="generator" content="GTK-Doc V1.6 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="chapter" href="glib.html" title="GLib Overview">
<link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
<link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
<link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
<link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
<link rel="chapter" href="tools.html" title="GLib Tools">
<link rel="index" href="ix01.html" title="Index">
<link rel="index" href="ix02.html" title="Index of deprecated symbols">
<link rel="index" href="ix03.html" title="Index of new symbols in 2.2">
<link rel="index" href="ix04.html" title="Index of new symbols in 2.4">
<link rel="index" href="ix05.html" title="Index of new symbols in 2.6">
<link rel="index" href="ix06.html" title="Index of new symbols in 2.8">
<link rel="index" href="ix07.html" title="Index of new symbols in 2.10">
<link rel="index" href="ix08.html" title="Index of new symbols in 2.12">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
<tr valign="middle">
<td><a accesskey="p" href="glib-Byte-Arrays.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="glib-data-types.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GLib Reference Manual</th>
<td><a accesskey="n" href="glib-N-ary-Trees.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr>
<tr><td colspan="5" class="shortcuts"><nobr><a href="#id3271307" class="shortcut">Top</a>
                  &#160;|&#160;
                  <a href="#id3271880" class="shortcut">Description</a></nobr></td></tr>
</table>
<div class="refentry" lang="en">
<a name="glib-Balanced-Binary-Trees"></a><div class="titlepage"></div>
<div class="refnamediv"><table width="100%"><tr>
<td valign="top">
<h2>
<a name="id3271307"></a><span class="refentrytitle">Balanced Binary Trees</span>
</h2>
<p>Balanced Binary Trees &#8212; a sorted collection of key/value pairs optimized for searching
and traversing in order.</p>
</td>
<td valign="top" align="right"></td>
</tr></table></div>
<div class="refsynopsisdiv">
<h2>Synopsis</h2>
<pre class="synopsis">

#include &lt;glib.h&gt;


            <a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>;
<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>*      <a href="glib-Balanced-Binary-Trees.html#g-tree-new">g_tree_new</a>                      (<a href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> key_compare_func);
<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>*      <a href="glib-Balanced-Binary-Trees.html#g-tree-new-with-data">g_tree_new_with_data</a>            (<a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> key_compare_func,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> key_compare_data);
<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>*      <a href="glib-Balanced-Binary-Trees.html#g-tree-new-full">g_tree_new_full</a>                 (<a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> key_compare_func,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> key_compare_data,
                                             <a href="glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> key_destroy_func,
                                             <a href="glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> value_destroy_func);
void        <a href="glib-Balanced-Binary-Trees.html#g-tree-insert">g_tree_insert</a>                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> key,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> value);
void        <a href="glib-Balanced-Binary-Trees.html#g-tree-replace">g_tree_replace</a>                  (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> key,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> value);
<a href="glib-Basic-Types.html#gint">gint</a>        <a href="glib-Balanced-Binary-Trees.html#g-tree-nnodes">g_tree_nnodes</a>                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);
<a href="glib-Basic-Types.html#gint">gint</a>        <a href="glib-Balanced-Binary-Trees.html#g-tree-height">g_tree_height</a>                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);
<a href="glib-Basic-Types.html#gpointer">gpointer</a>    <a href="glib-Balanced-Binary-Trees.html#g-tree-lookup">g_tree_lookup</a>                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> key);
<a href="glib-Basic-Types.html#gboolean">gboolean</a>    <a href="glib-Balanced-Binary-Trees.html#g-tree-lookup-extended">g_tree_lookup_extended</a>          (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> lookup_key,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> *orig_key,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> *value);
void        <a href="glib-Balanced-Binary-Trees.html#g-tree-foreach">g_tree_foreach</a>                  (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Balanced-Binary-Trees.html#GTraverseFunc">GTraverseFunc</a> func,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);
void        <a href="glib-Balanced-Binary-Trees.html#g-tree-traverse">g_tree_traverse</a>                 (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Balanced-Binary-Trees.html#GTraverseFunc">GTraverseFunc</a> traverse_func,
                                             <a href="glib-Balanced-Binary-Trees.html#GTraverseType">GTraverseType</a> traverse_type,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);
<a href="glib-Basic-Types.html#gboolean">gboolean</a>    (<a href="glib-Balanced-Binary-Trees.html#GTraverseFunc">*GTraverseFunc</a>)                (<a href="glib-Basic-Types.html#gpointer">gpointer</a> key,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> value,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> data);
enum        <a href="glib-Balanced-Binary-Trees.html#GTraverseType">GTraverseType</a>;
<a href="glib-Basic-Types.html#gpointer">gpointer</a>    <a href="glib-Balanced-Binary-Trees.html#g-tree-search">g_tree_search</a>                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> search_func,
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> user_data);
<a href="glib-Basic-Types.html#gboolean">gboolean</a>    <a href="glib-Balanced-Binary-Trees.html#g-tree-remove">g_tree_remove</a>                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> key);
<a href="glib-Basic-Types.html#gboolean">gboolean</a>    <a href="glib-Balanced-Binary-Trees.html#g-tree-steal">g_tree_steal</a>                    (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> key);
void        <a href="glib-Balanced-Binary-Trees.html#g-tree-destroy">g_tree_destroy</a>                  (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);
</pre>
</div>
<div class="refsect1" lang="en">
<a name="id3271880"></a><h2>Description</h2>
<p>
The <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> structure and its associated functions provide a sorted collection
of key/value pairs optimized for searching and traversing in order.
</p>
<p>
To create a new <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> use <a href="glib-Balanced-Binary-Trees.html#g-tree-new"><code class="function">g_tree_new()</code></a>.
</p>
<p>
To insert a key/value pair into a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> use <a href="glib-Balanced-Binary-Trees.html#g-tree-insert"><code class="function">g_tree_insert()</code></a>.
</p>
<p>
To lookup the value corresponding to a given key, use <a href="glib-Balanced-Binary-Trees.html#g-tree-lookup"><code class="function">g_tree_lookup()</code></a> and
<a href="glib-Balanced-Binary-Trees.html#g-tree-lookup-extended"><code class="function">g_tree_lookup_extended()</code></a>.
</p>
<p>
To find out the number of nodes in a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, use <a href="glib-Balanced-Binary-Trees.html#g-tree-nnodes"><code class="function">g_tree_nnodes()</code></a>.
To get the height of a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, use <a href="glib-Balanced-Binary-Trees.html#g-tree-height"><code class="function">g_tree_height()</code></a>.
</p>
<p>
To traverse a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, calling a function for each node visited in the
traversal, use <a href="glib-Balanced-Binary-Trees.html#g-tree-foreach"><code class="function">g_tree_foreach()</code></a>.
</p>
<p>
To remove a key/value pair use <a href="glib-Balanced-Binary-Trees.html#g-tree-remove"><code class="function">g_tree_remove()</code></a>.
</p>
<p>
To destroy a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, use <a href="glib-Balanced-Binary-Trees.html#g-tree-destroy"><code class="function">g_tree_destroy()</code></a>.
</p>
</div>
<div class="refsect1" lang="en">
<a name="id3272076"></a><h2>Details</h2>
<div class="refsect2" lang="en">
<a name="id3272086"></a><h3>
<a name="GTree"></a>GTree</h3>
<a class="indexterm" name="id3272098"></a><pre class="programlisting">typedef struct _GTree GTree;</pre>
<p>
The <span class="structname">GTree</span> struct is an opaque data structure representing a
<a href="glib-Balanced-Binary-Trees.html" title="Balanced Binary Trees">Balanced Binary Tree</a>.
It should be accessed only by using the following functions.
</p>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3272127"></a><h3>
<a name="g-tree-new"></a>g_tree_new ()</h3>
<a class="indexterm" name="id3272140"></a><pre class="programlisting"><a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>*      g_tree_new                      (<a href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> key_compare_func);</pre>
<p>
Creates a new <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>key_compare_func</code></em>&#160;:</span></td>
<td> the function used to order the nodes in the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
  It should return values similar to the standard <code class="function">strcmp()</code> function -
  0 if the two arguments are equal, a negative value if the first argument 
  comes before the second, or a positive value if the first argument comes 
  after the second.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td> a new <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3272238"></a><h3>
<a name="g-tree-new-with-data"></a>g_tree_new_with_data ()</h3>
<a class="indexterm" name="id3272251"></a><pre class="programlisting"><a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>*      g_tree_new_with_data            (<a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> key_compare_func,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> key_compare_data);</pre>
<p>
Creates a new <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> with a comparison function that accepts user data.
See <a href="glib-Balanced-Binary-Trees.html#g-tree-new"><code class="function">g_tree_new()</code></a> for more details.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>key_compare_func</code></em>&#160;:</span></td>
<td> <code class="function">qsort()</code>-style comparison function.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>key_compare_data</code></em>&#160;:</span></td>
<td> data to pass to comparison function.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td> a new <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3272372"></a><h3>
<a name="g-tree-new-full"></a>g_tree_new_full ()</h3>
<a class="indexterm" name="id3272385"></a><pre class="programlisting"><a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>*      g_tree_new_full                 (<a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> key_compare_func,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> key_compare_data,
                                             <a href="glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> key_destroy_func,
                                             <a href="glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> value_destroy_func);</pre>
<p>
Creates a new <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> like <a href="glib-Balanced-Binary-Trees.html#g-tree-new"><code class="function">g_tree_new()</code></a> and allows to specify functions 
to free the memory allocated for the key and value that get called when 
removing the entry from the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>key_compare_func</code></em>&#160;:</span></td>
<td> <code class="function">qsort()</code>-style comparison function.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>key_compare_data</code></em>&#160;:</span></td>
<td> data to pass to comparison function.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>key_destroy_func</code></em>&#160;:</span></td>
<td> a function to free the memory allocated for the key 
  used when removing the entry from the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if you don't
  want to supply such a function.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>value_destroy_func</code></em>&#160;:</span></td>
<td> a function to free the memory allocated for the 
  value used when removing the entry from the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if you 
  don't want to supply such a function.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td> a new <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3272599"></a><h3>
<a name="g-tree-insert"></a>g_tree_insert ()</h3>
<a class="indexterm" name="id3272612"></a><pre class="programlisting">void        g_tree_insert                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> key,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> value);</pre>
<p>
Inserts a key/value pair into a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>. If the given key already exists 
in the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> its corresponding value is set to the new value. If you 
supplied a value_destroy_func when creating the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, the old value is 
freed using that function. If you supplied a <em class="parameter"><code>key_destroy_func</code></em> when 
creating the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, the passed key is freed using that function.
</p>
<p>
The tree is automatically 'balanced' as new key/value pairs are added,
so that the distance from the root to every leaf is as small as possible.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>key</code></em>&#160;:</span></td>
<td> the key to insert.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>value</code></em>&#160;:</span></td>
<td> the value corresponding to the key.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3272760"></a><h3>
<a name="g-tree-replace"></a>g_tree_replace ()</h3>
<a class="indexterm" name="id3272773"></a><pre class="programlisting">void        g_tree_replace                  (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> key,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> value);</pre>
<p>
Inserts a new key and value into a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> similar to <a href="glib-Balanced-Binary-Trees.html#g-tree-insert"><code class="function">g_tree_insert()</code></a>. 
The difference is that if the key already exists in the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, it gets 
replaced by the new key. If you supplied a <em class="parameter"><code>value_destroy_func</code></em> when 
creating the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, the old value is freed using that function. If you 
supplied a <em class="parameter"><code>key_destroy_func</code></em> when creating the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, the old key is 
freed using that function. 
</p>
<p>
The tree is automatically 'balanced' as new key/value pairs are added,
so that the distance from the root to every leaf is as small as possible.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>key</code></em>&#160;:</span></td>
<td> the key to insert.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>value</code></em>&#160;:</span></td>
<td> the value corresponding to the key.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3272939"></a><h3>
<a name="g-tree-nnodes"></a>g_tree_nnodes ()</h3>
<a class="indexterm" name="id3272951"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a>        g_tree_nnodes                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);</pre>
<p>
Gets the number of nodes in a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td> the number of nodes in the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3273035"></a><h3>
<a name="g-tree-height"></a>g_tree_height ()</h3>
<a class="indexterm" name="id3273048"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a>        g_tree_height                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);</pre>
<p>
Gets the height of a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</p>
<p>
If the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> contains no nodes, the height is 0.
If the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> contains only one root node the height is 1.
If the root node has children the height is 2, etc.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td> the height of the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3273153"></a><h3>
<a name="g-tree-lookup"></a>g_tree_lookup ()</h3>
<a class="indexterm" name="id3273165"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gpointer">gpointer</a>    g_tree_lookup                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> key);</pre>
<p>
Gets the value corresponding to the given key. Since a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> is 
automatically balanced as key/value pairs are added, key lookup is very 
fast.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>key</code></em>&#160;:</span></td>
<td> the key to look up.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td> the value corresponding to the key, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if the key was
not found.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3273276"></a><h3>
<a name="g-tree-lookup-extended"></a>g_tree_lookup_extended ()</h3>
<a class="indexterm" name="id3273288"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_tree_lookup_extended          (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> lookup_key,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> *orig_key,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> *value);</pre>
<p>
Looks up a key in the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, returning the original key and the
associated value and a <a href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> which is <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the key was found. This 
is useful if you need to free the memory allocated for the original key, 
for example before calling <a href="glib-Balanced-Binary-Trees.html#g-tree-remove"><code class="function">g_tree_remove()</code></a>.</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>lookup_key</code></em>&#160;:</span></td>
<td> the key to look up.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>orig_key</code></em>&#160;:</span></td>
<td> returns the original key.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>value</code></em>&#160;:</span></td>
<td> returns the value associated with the key.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td> <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the key was found in the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3273478"></a><h3>
<a name="g-tree-foreach"></a>g_tree_foreach ()</h3>
<a class="indexterm" name="id3273490"></a><pre class="programlisting">void        g_tree_foreach                  (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Balanced-Binary-Trees.html#GTraverseFunc">GTraverseFunc</a> func,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre>
<p>
Calls the given function for each of the key/value pairs in the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
The function is passed the key and value of each pair, and the given
<em class="parameter"><code>data</code></em> parameter. The tree is traversed in sorted order.
</p>
<p>
The tree may not be modified while iterating over it (you can't 
add/remove items). To remove all items matching a predicate, you need 
to add each item to a list in your <a href="glib-Balanced-Binary-Trees.html#GTraverseFunc"><span class="type">GTraverseFunc</span></a> as you walk over 
the tree, then walk the list and remove each item.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>func</code></em>&#160;:</span></td>
<td> the function to call for each node visited. If this function
  returns <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, the traversal is stopped.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td>
<td> user data to pass to the function.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3273635"></a><h3>
<a name="g-tree-traverse"></a>g_tree_traverse ()</h3>
<a class="indexterm" name="id3273651"></a><pre class="programlisting">void        g_tree_traverse                 (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Balanced-Binary-Trees.html#GTraverseFunc">GTraverseFunc</a> traverse_func,
                                             <a href="glib-Balanced-Binary-Trees.html#GTraverseType">GTraverseType</a> traverse_type,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre>
<div class="warning" style="margin-left: 0.5in; margin-right: 0.5in;">
<h3 class="title">Warning</h3>
<p><code class="literal">g_tree_traverse</code> has been deprecated since version 2.2 and should not be used in newly-written code. The order of a balanced tree is somewhat arbitrary. If you 
just want to visit all nodes in sorted order, use <a href="glib-Balanced-Binary-Trees.html#g-tree-foreach"><code class="function">g_tree_foreach()</code></a> 
instead. If you really need to visit nodes in a different order, consider
using an <a href="glib-N-ary-Trees.html" title="N-ary Trees">N-ary Tree</a>.</p>
</div>
<p>
Calls the given function for each node in the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>traverse_func</code></em>&#160;:</span></td>
<td> the function to call for each node visited. If this 
  function returns <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, the traversal is stopped.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>traverse_type</code></em>&#160;:</span></td>
<td> the order in which nodes are visited, one of <a href="glib-Balanced-Binary-Trees.html#G-IN-ORDER:CAPS"><code class="literal">G_IN_ORDER</code></a>,
  <a href="glib-Balanced-Binary-Trees.html#G-PRE-ORDER:CAPS"><code class="literal">G_PRE_ORDER</code></a> and <a href="glib-Balanced-Binary-Trees.html#G-POST-ORDER:CAPS"><code class="literal">G_POST_ORDER</code></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td>
<td> user data to pass to the function.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3273864"></a><h3>
<a name="GTraverseFunc"></a>GTraverseFunc ()</h3>
<a class="indexterm" name="id3273877"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    (*GTraverseFunc)                (<a href="glib-Basic-Types.html#gpointer">gpointer</a> key,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> value,
                                             <a href="glib-Basic-Types.html#gpointer">gpointer</a> data);</pre>
<p>
Specifies the type of function passed to <a href="glib-Balanced-Binary-Trees.html#g-tree-traverse"><code class="function">g_tree_traverse()</code></a>.
It is passed the key and value of each node, together with
the <em class="parameter"><code>user_data</code></em> parameter passed to <a href="glib-Balanced-Binary-Trees.html#g-tree-traverse"><code class="function">g_tree_traverse()</code></a>.
If the function returns <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, the traversal is stopped.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>key</code></em>&#160;:</span></td>
<td>a key of a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> node.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>value</code></em>&#160;:</span></td>
<td>the value corresponding to the key.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>data</code></em>&#160;:</span></td>
<td>user data passed to <a href="glib-Balanced-Binary-Trees.html#g-tree-traverse"><code class="function">g_tree_traverse()</code></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td>
<a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> to stop the traversal.


</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3274045"></a><h3>
<a name="GTraverseType"></a>enum GTraverseType</h3>
<a class="indexterm" name="id3274058"></a><pre class="programlisting">typedef enum
{
  G_IN_ORDER,
  G_PRE_ORDER,
  G_POST_ORDER,
  G_LEVEL_ORDER
} GTraverseType;
</pre>
<p>
Specifies the type of traveral performed by <a href="glib-Balanced-Binary-Trees.html#g-tree-traverse"><code class="function">g_tree_traverse()</code></a>,
<a href="glib-N-ary-Trees.html#g-node-traverse"><code class="function">g_node_traverse()</code></a> and <a href="glib-N-ary-Trees.html#g-node-find"><code class="function">g_node_find()</code></a>.
</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><a name="G-IN-ORDER:CAPS"></a><code class="literal">G_IN_ORDER</code></span></td>
<td>vists a node's left child first, then the node itself, then its
  right child. This is the one to use if you want the output sorted according
  to the compare function.
</td>
</tr>
<tr>
<td>
<span class="term"><a name="G-PRE-ORDER:CAPS"></a><code class="literal">G_PRE_ORDER</code></span></td>
<td>visits a node, then its children.
</td>
</tr>
<tr>
<td>
<span class="term"><a name="G-POST-ORDER:CAPS"></a><code class="literal">G_POST_ORDER</code></span></td>
<td>visits the node's children, then the node itself.
</td>
</tr>
<tr>
<td>
<span class="term"><a name="G-LEVEL-ORDER:CAPS"></a><code class="literal">G_LEVEL_ORDER</code></span></td>
<td>is not implemented for
  <a href="glib-Balanced-Binary-Trees.html" title="Balanced Binary Trees">Balanced Binary Trees</a>.
  For <a href="glib-N-ary-Trees.html" title="N-ary Trees">N-ary Trees</a>, it vists the root
  node first, then its children, then its grandchildren, and so on. Note that
  this is less efficient than the other orders.

</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3274220"></a><h3>
<a name="g-tree-search"></a>g_tree_search ()</h3>
<a class="indexterm" name="id3274233"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gpointer">gpointer</a>    g_tree_search                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> search_func,
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> user_data);</pre>
<p>
Searches a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> using <em class="parameter"><code>search_func</code></em>.
</p>
<p>
The <em class="parameter"><code>search_func</code></em> is called with a pointer to the key of a key/value pair in 
the tree, and the passed in <em class="parameter"><code>user_data</code></em>. If <em class="parameter"><code>search_func</code></em> returns 0 for a 
key/value pair, then <code class="function">g_tree_search_func()</code> will return the value of that 
pair. If <em class="parameter"><code>search_func</code></em> returns -1,  searching will proceed among the 
key/value pairs that have a smaller key; if <em class="parameter"><code>search_func</code></em> returns 1, 
searching will proceed among the key/value pairs that have a larger key.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>search_func</code></em>&#160;:</span></td>
<td> a function used to search the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>. 
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>user_data</code></em>&#160;:</span></td>
<td> the data passed as the second argument to the <em class="parameter"><code>search_func</code></em> 
function.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td> the value corresponding to the found key, or <a href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if the key 
was not found.
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3274435"></a><h3>
<a name="g-tree-remove"></a>g_tree_remove ()</h3>
<a class="indexterm" name="id3274448"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_tree_remove                   (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> key);</pre>
<p>
Removes a key/value pair from a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</p>
<p>
If the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> was created using <a href="glib-Balanced-Binary-Trees.html#g-tree-new-full"><code class="function">g_tree_new_full()</code></a>, the key and value 
are freed using the supplied destroy functions, otherwise you have to 
make sure that any dynamically allocated values are freed yourself.
If the key does not exist in the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, the function does nothing.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>key</code></em>&#160;:</span></td>
<td> the key to remove.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td> <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the key was found (prior to 2.8, this function returned 
  nothing)
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3274590"></a><h3>
<a name="g-tree-steal"></a>g_tree_steal ()</h3>
<a class="indexterm" name="id3274603"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_tree_steal                    (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree,
                                             <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> key);</pre>
<p>
Removes a key and its associated value from a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> without calling 
the key and value destroy functions.
</p>
<p>
If the key does not exist in the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, the function does nothing.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody>
<tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr>
<tr>
<td>
<span class="term"><em class="parameter"><code>key</code></em>&#160;:</span></td>
<td> the key to remove.
</td>
</tr>
<tr>
<td>
<span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td>
<td> <a href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the key was found (prior to 2.8, this function returned 
   nothing)
</td>
</tr>
</tbody>
</table></div>
</div>
<hr>
<div class="refsect2" lang="en">
<a name="id3274726"></a><h3>
<a name="g-tree-destroy"></a>g_tree_destroy ()</h3>
<a class="indexterm" name="id3274738"></a><pre class="programlisting">void        g_tree_destroy                  (<a href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);</pre>
<p>
Destroys the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>. If keys and/or values are dynamically allocated, you 
should either free them first or create the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> using <a href="glib-Balanced-Binary-Trees.html#g-tree-new-full"><code class="function">g_tree_new_full()</code></a>.
In the latter case the destroy functions you supplied will be called on 
all keys and values before destroying the <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.</p>
<p>

</p>
<div class="variablelist"><table border="0">
<col align="left" valign="top">
<tbody><tr>
<td>
<span class="term"><em class="parameter"><code>tree</code></em>&#160;:</span></td>
<td> a <a href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.
</td>
</tr></tbody>
</table></div>
</div>
</div>
</div>
</body>
</html>