📄 glib-hash-tables.html
字号:
<td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the hash value corresponding to the key.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3138212"></a><h3><a name="GEqualFunc"></a>GEqualFunc ()</h3><a class="indexterm" name="id3138222"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> (*GEqualFunc) (<a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> a, <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> b);</pre><p>Specifies the type of a function used to test two values forequality. The function should return <code class="literal">TRUE</code> if both values are equal and<code class="literal">FALSE</code> otherwise.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>a</code></em> :</span></td><td>a value.</td></tr><tr><td><span class="term"><em class="parameter"><code>b</code></em> :</span></td><td>a value to compare with.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td><code class="literal">TRUE</code> if <em class="parameter"><code>a</code></em> = <em class="parameter"><code>b</code></em>; <code class="literal">FALSE</code> otherwise.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3138336"></a><h3><a name="g-hash-table-insert"></a>g_hash_table_insert ()</h3><a class="indexterm" name="id3138347"></a><pre class="programlisting">void g_hash_table_insert (<a href="glib-Hash-Tables.html#GHashTable">GHashTable</a> *hash_table, <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-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>.</p><p>If the key already exists in the <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a> its current value is replacedwith the new value. If you supplied a <em class="parameter"><code>value_destroy_func</code></em> when creating the <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>, the old value is freed using that function. If you supplieda <em class="parameter"><code>key_destroy_func</code></em> when creating the <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>, the passed key is freed using that function.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>hash_table</code></em> :</span></td><td> a <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>key</code></em> :</span></td><td> a key to insert.</td></tr><tr><td><span class="term"><em class="parameter"><code>value</code></em> :</span></td><td> the value to associate with the key.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3138499"></a><h3><a name="g-hash-table-replace"></a>g_hash_table_replace ()</h3><a class="indexterm" name="id3138510"></a><pre class="programlisting">void g_hash_table_replace (<a href="glib-Hash-Tables.html#GHashTable">GHashTable</a> *hash_table, <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-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a> similar to <a href="glib-Hash-Tables.html#g-hash-table-insert"><code class="function">g_hash_table_insert()</code></a>. The difference is that if the key already exists in the <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</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-Hash-Tables.html#GHashTable"><span class="type">GHashTable</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-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>, the old key is freed using that function.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>hash_table</code></em> :</span></td><td> a <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>key</code></em> :</span></td><td> a key to insert.</td></tr><tr><td><span class="term"><em class="parameter"><code>value</code></em> :</span></td><td> the value to associate with the key.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3138669"></a><h3><a name="g-hash-table-size"></a>g_hash_table_size ()</h3><a class="indexterm" name="id3138680"></a><pre class="programlisting"><a href="glib-Basic-Types.html#guint">guint</a> g_hash_table_size (<a href="glib-Hash-Tables.html#GHashTable">GHashTable</a> *hash_table);</pre><p>Returns the number of elements contained in the <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</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>hash_table</code></em> :</span></td><td> a <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> the number of key/value pairs in the <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3138764"></a><h3><a name="g-hash-table-lookup"></a>g_hash_table_lookup ()</h3><a class="indexterm" name="id3138775"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gpointer">gpointer</a> g_hash_table_lookup (<a href="glib-Hash-Tables.html#GHashTable">GHashTable</a> *hash_table, <a href="glib-Basic-Types.html#gconstpointer">gconstpointer</a> key);</pre><p>Looks up a key in a <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>. Note that this function cannotdistinguish between a key that is not present and one which is presentand has the value <code class="literal">NULL</code>. If you need this distinction, use<a href="glib-Hash-Tables.html#g-hash-table-lookup-extended"><code class="function">g_hash_table_lookup_extended()</code></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>hash_table</code></em> :</span></td><td> a <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</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 associated value, or <code class="literal">NULL</code> if the key is not found.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3138898"></a><h3><a name="g-hash-table-lookup-extended"></a>g_hash_table_lookup_extended ()</h3><a class="indexterm" name="id3138909"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a> g_hash_table_lookup_extended (<a href="glib-Hash-Tables.html#GHashTable">GHashTable</a> *hash_table, <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-Hash-Tables.html#GHashTable"><span class="type">GHashTable</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-Hash-Tables.html#g-hash-table-remove"><code class="function">g_hash_table_remove()</code></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>hash_table</code></em> :</span></td><td> a <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</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-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3139092"></a><h3><a name="g-hash-table-foreach"></a>g_hash_table_foreach ()</h3><a class="indexterm" name="id3139103"></a><pre class="programlisting">void g_hash_table_foreach (<a href="glib-Hash-Tables.html#GHashTable">GHashTable</a> *hash_table, <a href="glib-Hash-Tables.html#GHFunc">GHFunc</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-Hash-Tables.html#GHashTable"><span class="type">GHashTable</span></a>. The function is passed the key and value of eachpair, and the given <em class="parameter"><code>user_data</code></em> parameter. The hash table may notbe modified while iterating over it (you can't add/removeitems). To remove all items matching a predicate, use<a href="glib-Hash-Tables.html#g-hash-table-remove"><code class="function">g_hash_table_remove()</code></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>hash_table</code></em> :</span></td><td> a <a href="glib-Hash-Tables.html#GHashTable"><span class="type">GHashTable</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 key/value pair.</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="id3139233"></a><h3>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -