📄 glib-balanced-binary-trees.html
字号:
<td><span class="term"><em class="parameter"><code>tree</code></em> :</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> :</span></td><td> the key to insert.</td></tr><tr><td><span class="term"><em class="parameter"><code>value</code></em> :</span></td><td> the value corresponding to the key.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3172100"></a><h3><a name="g-tree-replace"></a>g_tree_replace ()</h3><a class="indexterm" name="id3172110"></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> :</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> :</span></td><td> the key to insert.</td></tr><tr><td><span class="term"><em class="parameter"><code>value</code></em> :</span></td><td> the value corresponding to the key.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3172276"></a><h3><a name="g-tree-nnodes"></a>g_tree_nnodes ()</h3><a class="indexterm" name="id3172286"></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> :</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> :</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="id3172369"></a><h3><a name="g-tree-height"></a>g_tree_height ()</h3><a class="indexterm" name="id3172380"></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> :</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> :</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="id3172485"></a><h3><a name="g-tree-lookup"></a>g_tree_lookup ()</h3><a class="indexterm" name="id3172495"></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> :</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> :</span></td><td> the key to look up.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the value corresponding to the key, or <code class="literal">NULL</code> if the key wasnot found.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3172601"></a><h3><a name="g-tree-lookup-extended"></a>g_tree_lookup_extended ()</h3><a class="indexterm" name="id3172612"></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 theassociated value and a <a href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> which is <code class="literal">TRUE</code> 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> :</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> :</span></td><td> the key to look up.</td></tr><tr><td><span class="term"><em class="parameter"><code>orig_key</code></em> :</span></td><td> returns the original key.</td></tr><tr><td><span class="term"><em class="parameter"><code>value</code></em> :</span></td><td> returns the value associated with the key.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> <code class="literal">TRUE</code> 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="id3172793"></a><h3><a name="g-tree-foreach"></a>g_tree_foreach ()</h3><a class="indexterm" name="id3172803"></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> :</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> :</span></td><td> the function to call for each node visited. If this function returns <code class="literal">TRUE</code>, the traversal is stopped.</td></tr><tr><td><span class="term"><em class="parameter"><code>user_data</code></em> :</span></td><td> user data to pass to the function.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3172944"></a><h3><a name="g-tree-traverse"></a>g_tree_traverse ()</h3><a class="indexterm" name="id3172954"></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> is deprecated 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, considerusing 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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -