📄 glib-balanced-binary-trees.html
字号:
<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="id3330511"></a><h3><a name="g-tree-new-full"></a>g_tree_new_full ()</h3><a class="indexterm" name="id3330524"></a><pre class="programlisting"><a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a>* g_tree_new_full (<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);</pre><p>Creates a new <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> like <a class="link" 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 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> <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"><em class="parameter"><code>key_destroy_func</code></em> :</span></p></td><td> a function to free the memory allocated for the key used when removing the entry from the <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> or <a class="link" 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><p><span class="term"><em class="parameter"><code>value_destroy_func</code></em> :</span></p></td><td> a function to free the memory allocated for the value used when removing the entry from the <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> or <a class="link" 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><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="id3330740"></a><h3><a name="g-tree-insert"></a>g_tree_insert ()</h3><a class="indexterm" name="id3330752"></a><pre class="programlisting">void g_tree_insert (<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);</pre><p>Inserts a key/value pair into a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>. If the given key already exists in the <a class="link" 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 class="link" 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 class="link" 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><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 insert.</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></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3330902"></a><h3><a name="g-tree-replace"></a>g_tree_replace ()</h3><a class="indexterm" name="id3330914"></a><pre class="programlisting">void g_tree_replace (<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);</pre><p>Inserts a new key and value into a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> similar to <a class="link" 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 class="link" 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 class="link" 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 class="link" 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><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 insert.</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></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3331080"></a><h3><a name="g-tree-nnodes"></a>g_tree_nnodes ()</h3><a class="indexterm" name="id3331093"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint">gint</a> g_tree_nnodes (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);</pre><p>Gets the number of nodes in a <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"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the number of nodes 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="id3331177"></a><h3><a name="g-tree-height"></a>g_tree_height ()</h3><a class="indexterm" name="id3331190"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint">gint</a> g_tree_height (<a class="link" href="glib-Balanced-Binary-Trees.html#GTree">GTree</a> *tree);</pre><p>Gets the height of a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a>.</p><p>If the <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> contains no nodes, the height is 0.If the <a class="link" 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><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"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> the height of 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="id3331295"></a><h3><a name="g-tree-lookup"></a>g_tree_lookup ()</h3><a class="indexterm" name="id3331308"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer">gpointer</a> g_tree_lookup (<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);</pre><p>Gets the value corresponding to the given key. Since a <a class="link" href="glib-Balanced-Binary-Trees.html#GTree"><span class="type">GTree</span></a> is
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -