📄 glib-balanced-binary-trees.html
字号:
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><p><span class="term"><em class="parameter"><code>tree</code></em> :</span></p></td><td> a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>key</code></em> :</span></p></td><td> the key to look up.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the value corresponding to the key, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> if the key wasnot found.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3331419"></a><h3><a name="g-tree-lookup-extended"></a>g_tree_lookup_extended ()</h3><a class="indexterm" name="id3331431"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> g_tree_lookup_extended (<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);</pre><p>Looks up a key in the <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>, returning the original key and theassociated value and a <a class="link" href="glib-Basic-Types.html#gboolean"><span class="type">gboolean</span></a> which is <a class="link" 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 class="link" 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><p><span class="term"><em class="parameter"><code>tree</code></em> :</span></p></td><td> a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>lookup_key</code></em> :</span></p></td><td> the key to look up.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>orig_key</code></em> :</span></p></td><td> returns the original key.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>value</code></em> :</span></p></td><td> returns the value associated with the key.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the key was found in the <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="id3331622"></a><h3><a name="g-tree-foreach"></a>g_tree_foreach ()</h3><a class="indexterm" name="id3331635"></a><pre class="programlisting">void g_tree_foreach (<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);</pre><p>Calls the given function for each of the key/value pairs in the <a class="link" 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 class="link" 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><p><span class="term"><em class="parameter"><code>tree</code></em> :</span></p></td><td> a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>func</code></em> :</span></p></td><td> the function to call for each node visited. If this function returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, the traversal is stopped.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td><td> user data to pass to the function.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3331780"></a><h3><a name="g-tree-traverse"></a>g_tree_traverse ()</h3><a class="indexterm" name="id3331796"></a><pre class="programlisting">void g_tree_traverse (<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);</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 class="link" 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 class="link" 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 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>tree</code></em> :</span></p></td><td> a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>traverse_func</code></em> :</span></p></td><td> the function to call for each node visited. If this function returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>, the traversal is stopped.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>traverse_type</code></em> :</span></p></td><td> the order in which nodes are visited, one of <a class="link" href="glib-Balanced-Binary-Trees.html#G-IN-ORDER:CAPS"><code class="literal">G_IN_ORDER</code></a>, <a class="link" href="glib-Balanced-Binary-Trees.html#G-PRE-ORDER:CAPS"><code class="literal">G_PRE_ORDER</code></a> and <a class="link" href="glib-Balanced-Binary-Trees.html#G-POST-ORDER:CAPS"><code class="literal">G_POST_ORDER</code></a>.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td><td> user data to pass to the function.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3332010"></a><h3><a name="GTraverseFunc"></a>GTraverseFunc ()</h3><a class="indexterm" name="id3332023"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> (*GTraverseFunc) (<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);</pre><p>Specifies the type of function passed to <a class="link" 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 class="link" href="glib-Balanced-Binary-Trees.html#g-tree-traverse"><code class="function">g_tree_traverse()</code></a>.If the function returns <a class="link" 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><p><span class="term"><em class="parameter"><code>key</code></em> :</span></p></td><td>a key of a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> node.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>value</code></em> :</span></p></td><td>the value corresponding to the key.</td></tr><tr><td><p><span class="term"><em class="parameter"><code>data</code></em> :</span></p></td><td>user data passed to <a class="link" href="glib-Balanced-Binary-Trees.html#g-tree-traverse"><code class="function">g_tree_traverse()</code></a>.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td><a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> to stop the traversal.</td></tr></tbody></table></div></div><hr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -