?? 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.73.2"><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.9 (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"><link rel="index" href="ix09.html" title="Index of new symbols in 2.14"><link rel="index" href="ix10.html" title="Index of new symbols in 2.16"></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="#id3329437" class="shortcut">Top</a>  |  <a href="#id3330019" 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="id3329437"></a><span class="refentrytitle">Balanced Binary Trees</span></h2><p>Balanced Binary Trees — a sorted collection of key/value pairs optimized for searchingand traversing in order</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <glib.h> <a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>;<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>* <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-new">g_tree_new</a> (<a class="link" href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> key_compare_func);<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>* <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-new-with-data">g_tree_new_with_data</a> (<a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> key_compare_func, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> key_compare_data);<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>* <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-new-full">g_tree_new_full</a> (<a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> key_compare_func, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> key_compare_data, <a class="link" href="glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> key_destroy_func, <a class="link" href="glib-Datasets.html#GDestroyNotify">GDestroyNotify</a> value_destroy_func);void <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-insert">g_tree_insert</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> key, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> value);void <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-replace">g_tree_replace</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> key, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> value);<a class="link" href="glib-Basic-Types.html#gint">gint</a> <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-nnodes">g_tree_nnodes</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);<a class="link" href="glib-Basic-Types.html#gint">gint</a> <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-height">g_tree_height</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-lookup">g_tree_lookup</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree, <a class="link" href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> key);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-lookup-extended">g_tree_lookup_extended</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree, <a class="link" href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> lookup_key, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> *orig_key, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> *value);void <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-foreach">g_tree_foreach</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree, <a class="link" href="glib-Balanced-Binary-Trees.html#GTraverseFunc">GTraverseFunc</a> func, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);void <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-traverse">g_tree_traverse</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree, <a class="link" href="glib-Balanced-Binary-Trees.html#GTraverseFunc">GTraverseFunc</a> traverse_func, <a class="link" href="glib-Balanced-Binary-Trees.html#GTraverseType">GTraverseType</a> traverse_type, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTraverseFunc">*GTraverseFunc</a>) (<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> key, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> value, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> data);enum <a class="link" href="glib-Balanced-Binary-Trees.html#GTraverseType">GTraverseType</a>;<a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-search">g_tree_search</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree, <a class="link" href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> search_func, <a class="link" href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> user_data);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-remove">g_tree_remove</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree, <a class="link" href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> key);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-steal">g_tree_steal</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree, <a class="link" href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> key);void <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-destroy">g_tree_destroy</a> (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);</pre></div><div class="refsect1" lang="en"><a name="id3330019"></a><h2>Description</h2><p>The <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> structure and its associated functions provide a sorted collectionof key/value pairs optimized for searching and traversing in order.</p><p>To create a new <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> use <a class="link" 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 class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> use <a class="link" 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 class="link" href="glib-Balanced-Binary-Trees.html#g-tree-lookup"><code class="function">g_tree_lookup()</code></a> and<a class="link" 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 class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, use <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-nnodes"><code class="function">g_tree_nnodes()</code></a>.To get the height of a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, use <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-height"><code class="function">g_tree_height()</code></a>.</p><p>To traverse a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, calling a function for each node visited in thetraversal, use <a class="link" 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 class="link" href="glib-Balanced-Binary-Trees.html#g-tree-remove"><code class="function">g_tree_remove()</code></a>.</p><p>To destroy a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, use <a class="link" 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="id3330214"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3330224"></a><h3><a name="GTree"></a>GTree</h3><a class="indexterm" name="id3330237"></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 class="link" 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="id3330266"></a><h3><a name="g-tree-new"></a>g_tree_new ()</h3><a class="indexterm" name="id3330278"></a><pre class="programlisting"><a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>* g_tree_new (<a class="link" href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> key_compare_func);</pre><p>Creates a new <a class="link" 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><p><span class="term"><em class="parameter"><code>key_compare_func</code></em> :</span></p></td><td> the function used to order the nodes in the <a class="link" 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><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> a new <a class="link" 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="id3330377"></a><h3><a name="g-tree-new-with-data"></a>g_tree_new_with_data ()</h3><a class="indexterm" name="id3330390"></a><pre class="programlisting"><a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>* g_tree_new_with_data (<a class="link" href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> key_compare_func, <a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> key_compare_data);</pre><p>Creates a new <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> with a comparison function that accepts user data.See <a class="link" 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><p><span class="term"><em class="parameter"><code>key_compare_func</code></em> :</span></p></td><td> <code class="function">qsort()</code>-style comparison function.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>key_compare_data</code></em> :</span></p></td><td> data to pass to comparison function.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -