📄 glib-arrays.html
字号:
</div><hr><div class="refsect2" lang="en"><a name="id3158777"></a><h3><a name="g-array-remove-index-fast"></a>g_array_remove_index_fast ()</h3><a class="indexterm" name="id3158789"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>* g_array_remove_index_fast (<a href="glib-Arrays.html#GArray">GArray</a> *array, <a href="glib-Basic-Types.html#guint">guint</a> index_);</pre><p>Removes the element at the given index from a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.The last element in the array is used to fill in the space, so this functiondoes not preserve the order of the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>. But it is faster than<a href="glib-Arrays.html#g-array-remove-index"><code class="function">g_array_remove_index()</code></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>array</code></em> :</span></td><td>a <em class="parameter"><code>GArray</code></em>.</td></tr><tr><td><span class="term"><em class="parameter"><code>index_</code></em> :</span></td><td>the index of the element to remove.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3158910"></a><h3><a name="g-array-remove-range"></a>g_array_remove_range ()</h3><a class="indexterm" name="id3158921"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>* g_array_remove_range (<a href="glib-Arrays.html#GArray">GArray</a> *array, <a href="glib-Basic-Types.html#guint">guint</a> index_, <a href="glib-Basic-Types.html#guint">guint</a> length);</pre><p>Removes the given number of elements starting at the given index from a<a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>. The following elements are moved to close the gap.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>array</code></em> :</span></td><td>a <em class="parameter"><code>GArray</code></em>.</td></tr><tr><td><span class="term"><em class="parameter"><code>index_</code></em> :</span></td><td>the index of the first element to remove.</td></tr><tr><td><span class="term"><em class="parameter"><code>length</code></em> :</span></td><td>the number of elements to remove.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.</td></tr></tbody></table></div><p>Since 2.4</p></div><hr><div class="refsect2" lang="en"><a name="id3159049"></a><h3><a name="g-array-sort"></a>g_array_sort ()</h3><a class="indexterm" name="id3159059"></a><pre class="programlisting">void g_array_sort (<a href="glib-Arrays.html#GArray">GArray</a> *array, <a href="glib-Doubly-Linked-Lists.html#GCompareFunc">GCompareFunc</a> compare_func);</pre><p>Sorts a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a> using <em class="parameter"><code>compare_func</code></em> which should be a <code class="function">qsort()</code>-style comparisonfunction (returns -1 for first arg is less than second arg, 0 for equal, 1 iffirst arg is greater than second arg).</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>array</code></em> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>compare_func</code></em> :</span></td><td>comparison function.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3159162"></a><h3><a name="g-array-sort-with-data"></a>g_array_sort_with_data ()</h3><a class="indexterm" name="id3159173"></a><pre class="programlisting">void g_array_sort_with_data (<a href="glib-Arrays.html#GArray">GArray</a> *array, <a href="glib-Doubly-Linked-Lists.html#GCompareDataFunc">GCompareDataFunc</a> compare_func, <a href="glib-Basic-Types.html#gpointer">gpointer</a> user_data);</pre><p>Like <a href="glib-Arrays.html#g-array-sort"><code class="function">g_array_sort()</code></a>, but the comparison function receives a user dataargument.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>array</code></em> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>compare_func</code></em> :</span></td><td>comparison function.</td></tr><tr><td><span class="term"><em class="parameter"><code>user_data</code></em> :</span></td><td>data to pass to <em class="parameter"><code>compare_func</code></em>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3159289"></a><h3><a name="g-array-index"></a>g_array_index()</h3><a class="indexterm" name="id3159300"></a><pre class="programlisting">#define g_array_index(a,t,i)</pre><p>Returns the element of a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a> at the given index.The return value is cast to the given type.</p><div class="example"><a name="id3159323"></a><p class="title"><b>Example 4. Getting a pointer to an element in a <span class="structname">GArray</span></b></p><pre class="programlisting"> EDayViewEvent *event; /* This gets a pointer to the 3rd element in the array of EDayViewEvent structs. */ event = &g_array_index (events, EDayViewEvent, 3);</pre></div><p></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 <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>t</code></em> :</span></td><td>the type of the elements.</td></tr><tr><td><span class="term"><em class="parameter"><code>i</code></em> :</span></td><td>the index of the element to return.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the element of the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a> at the index given by <em class="parameter"><code>i</code></em>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3159422"></a><h3><a name="g-array-set-size"></a>g_array_set_size ()</h3><a class="indexterm" name="id3159433"></a><pre class="programlisting"><a href="glib-Arrays.html#GArray">GArray</a>* g_array_set_size (<a href="glib-Arrays.html#GArray">GArray</a> *array, <a href="glib-Basic-Types.html#guint">guint</a> length);</pre><p>Sets the size of the array, expanding it if necessary.If the array was created with <em class="parameter"><code>clear_</code></em> set to <code class="literal">TRUE</code>, the new elements are set to 0.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>array</code></em> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>length</code></em> :</span></td><td>the new size of the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3159548"></a><h3><a name="g-array-free"></a>g_array_free ()</h3><a class="indexterm" name="id3159559"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>* g_array_free (<a href="glib-Arrays.html#GArray">GArray</a> *array, <a href="glib-Basic-Types.html#gboolean">gboolean</a> free_segment);</pre><p>Frees the memory allocated for the <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.If <em class="parameter"><code>free_segment</code></em> is <code class="literal">TRUE</code> it frees the actual element data as well.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>array</code></em> :</span></td><td>a <a href="glib-Arrays.html#GArray"><span class="type">GArray</span></a>.</td></tr><tr><td><span class="term"><em class="parameter"><code>free_segment</code></em> :</span></td><td>if <code class="literal">TRUE</code> the actual element data is freed as well.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td>the element data if <em class="parameter"><code>free_segment</code></em> is <code class="literal">FALSE</code>, otherwise <code class="literal">NULL</code></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-String-Chunks.html"><b><< String Chunks</b></a></td><td align="right"><a accesskey="n" href="glib-Pointer-Arrays.html"><b>Pointer Arrays >></b></a></td></tr></table></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -