📄 glib-balanced-binary-trees.html
字号:
<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>traverse_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>traverse_type</code></em> :</span></td><td> the order in which nodes are visited, one of <code class="literal">G_IN_ORDER</code>, <code class="literal">G_PRE_ORDER</code> and <code class="literal">G_POST_ORDER</code>.</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="id3173147"></a><h3><a name="GTraverseFunc"></a>GTraverseFunc ()</h3><a class="indexterm" name="id3173157"></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 withthe <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 <code class="literal">TRUE</code>, 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> :</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> :</span></td><td>the value corresponding to the key.</td></tr><tr><td><span class="term"><em class="parameter"><code>data</code></em> :</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> :</span></td><td><code class="literal">TRUE</code> to stop the traversal.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3173316"></a><h3><a name="GTraverseType"></a>enum GTraverseType</h3><a class="indexterm" name="id3173327"></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"><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"><code class="literal">G_PRE_ORDER</code></span></td><td>visits a node, then its children.</td></tr><tr><td><span class="term"><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"><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="id3173461"></a><h3><a name="g-tree-search"></a>g_tree_search ()</h3><a class="indexterm" name="id3173472"></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> :</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> :</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> :</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> :</span></td><td> the value corresponding to the found key, or <code class="literal">NULL</code> if the key was not found.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3173670"></a><h3><a name="g-tree-remove"></a>g_tree_remove ()</h3><a class="indexterm" name="id3173680"></a><pre class="programlisting">void 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> :</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 remove.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3173801"></a><h3><a name="g-tree-steal"></a>g_tree_steal ()</h3><a class="indexterm" name="id3173812"></a><pre class="programlisting">void 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> :</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 remove.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3173912"></a><h3><a name="g-tree-destroy"></a>g_tree_destroy ()</h3><a class="indexterm" name="id3173923"></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> :</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><table class="navigation" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle"><td align="left"><a accesskey="p" href="glib-Byte-Arrays.html"><b><< Byte Arrays</b></a></td><td align="right"><a accesskey="n" href="glib-N-ary-Trees.html"><b>N-ary Trees >></b></a></td></tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -