![]() |
![]() |
![]() |
GLib Reference Manual | ![]() |
---|---|---|---|---|
Top | Description |
#include <glib.h> GQueue; GQueue* g_queue_new (void); void g_queue_free (GQueue *queue); #define G_QUEUE_INIT void g_queue_init (GQueue *queue); void g_queue_clear (GQueue *queue); gboolean g_queue_is_empty (GQueue *queue); guint g_queue_get_length (GQueue *queue); void g_queue_reverse (GQueue *queue); GQueue * g_queue_copy (GQueue *queue); void g_queue_foreach (GQueue *queue, GFunc func, gpointer user_data); GList * g_queue_find (GQueue *queue, gconstpointer data); GList * g_queue_find_custom (GQueue *queue, gconstpointer data, GCompareFunc func); void g_queue_sort (GQueue *queue, GCompareDataFunc compare_func, gpointer user_data); void g_queue_push_head (GQueue *queue, gpointer data); void g_queue_push_tail (GQueue *queue, gpointer data); void g_queue_push_nth (GQueue *queue, gpointer data, gint n); gpointer g_queue_pop_head (GQueue *queue); gpointer g_queue_pop_tail (GQueue *queue); gpointer g_queue_pop_nth (GQueue *queue, guint n); gpointer g_queue_peek_head (GQueue *queue); gpointer g_queue_peek_tail (GQueue *queue); gpointer g_queue_peek_nth (GQueue *queue, guint n); gint g_queue_index (GQueue *queue, gconstpointer data); void g_queue_remove (GQueue *queue, gconstpointer data); void g_queue_remove_all (GQueue *queue, gconstpointer data); void g_queue_insert_before (GQueue *queue, GList *sibling, gpointer data); void g_queue_insert_after (GQueue *queue, GList *sibling, gpointer data); void g_queue_insert_sorted (GQueue *queue, gpointer data, GCompareDataFunc func, gpointer user_data); void g_queue_push_head_link (GQueue *queue, GList *link_); void g_queue_push_tail_link (GQueue *queue, GList *link_); void g_queue_push_nth_link (GQueue *queue, gint n, GList *link_); GList* g_queue_pop_head_link (GQueue *queue); GList* g_queue_pop_tail_link (GQueue *queue); GList* g_queue_pop_nth_link (GQueue *queue, guint n); GList* g_queue_peek_head_link (GQueue *queue); GList* g_queue_peek_tail_link (GQueue *queue); GList* g_queue_peek_nth_link (GQueue *queue, guint n); gint g_queue_link_index (GQueue *queue, GList *link_); void g_queue_unlink (GQueue *queue, GList *link_); void g_queue_delete_link (GQueue *queue, GList *link_);
void g_queue_free (GQueue *queue);
Frees the memory allocated for the GQueue. Only call this function if
queue
was created with g_queue_new()
. If queue elements contain
dynamically-allocated memory, they should be freed first.
|
a GQueue. |
void g_queue_init (GQueue *queue);
A statically-allocated GQueue must be initialized with this function
before it can be used. Alternatively you can initialize it with
G_QUEUE_INIT. It is not necessary to initialize queues created with
g_queue_new()
.
|
an uninitialized GQueue |
Since 2.14
void g_queue_clear (GQueue *queue);
Removes all the elements in queue
. If queue elements contain
dynamically-allocated memory, they should be freed first.
|
a GQueue |
Since 2.14
guint g_queue_get_length (GQueue *queue);
Returns the number of items in queue
.
|
a GQueue |
Returns : |
The number of items in queue .
|
Since 2.4
void g_queue_reverse (GQueue *queue);
Reverses the order of the items in queue
.
|
a GQueue |
Since 2.4
GQueue * g_queue_copy (GQueue *queue);
Copies a queue
. Note that is a shallow copy. If the elements in the
queue consist of pointers to data, the pointers are copied, but the
actual data is not.
|
a GQueue |
Returns : |
A copy of queue
|
Since 2.4
void g_queue_foreach (GQueue *queue, GFunc func, gpointer user_data);
Calls func
for each element in the queue passing user_data
to the
function.
|
a GQueue |
|
the function to call for each element's data |
|
user data to pass to func
|
Since 2.4
GList * g_queue_find (GQueue *queue, gconstpointer data);
Finds the first link in queue
which contains data
.
|
a GQueue |
|
data to find |
Returns : |
The first link in queue which contains data .
|
Since 2.4
GList * g_queue_find_custom (GQueue *queue, gconstpointer data, GCompareFunc func);
Finds an element in a GQueue, using a supplied function to find the desired element. It iterates over the queue, calling the given function which should return 0 when the desired element is found. The function takes two gconstpointer arguments, the GQueue element's data as the first argument and the given user data as the second argument.
|
a GQueue |
|
user data passed to func
|
|
a GCompareFunc to call for each element. It should return 0 when the desired element is found |
Returns : |
The found link, or NULL if it wasn't found
|
Since 2.4
void g_queue_sort (GQueue *queue, GCompareDataFunc compare_func, gpointer user_data);
Sorts queue
using compare_func
.
|
a GQueue |
|
the GCompareDataFunc used to sort queue . This function
is passed two elements of the queue and should return 0 if they are
equal, a negative value if the first comes before the second, and
a positive value if the second comes before the first.
|
|
user data passed to compare_func
|
Since 2.4
void g_queue_push_head (GQueue *queue, gpointer data);
Adds a new element at the head of the queue.
|
a GQueue. |
|
the data for the new element. |
void g_queue_push_tail (GQueue *queue, gpointer data);
Adds a new element at the tail of the queue.
|
a GQueue. |
|
the data for the new element. |
void g_queue_push_nth (GQueue *queue, gpointer data, gint n);
Inserts a new element into queue
at the given position
|
a GQueue |
|
the data for the new element |
|
the position to insert the new element. If n is negative or
larger than the number of elements in the queue , the element is
added to the end of the queue.
|
Since 2.4
gpointer g_queue_pop_head (GQueue *queue);
Removes the first element of the queue.
gpointer g_queue_pop_tail (GQueue *queue);
Removes the last element of the queue.
gpointer g_queue_pop_nth (GQueue *queue, guint n);
Removes the n
'th element of queue
.
|
a GQueue |
|
the position of the element. |
Returns : |
the element's data, or NULL if n is off the end of queue .
|
Since 2.4
gpointer g_queue_peek_head (GQueue *queue);
Returns the first element of the queue.
gpointer g_queue_peek_tail (GQueue *queue);
Returns the last element of the queue.
gpointer g_queue_peek_nth (GQueue *queue, guint n);
Returns the n
'th element of queue
.
|
a GQueue |
|
the position of the element. |
Returns : |
The data for the n 'th element of queue , or NULL if n is
off the end of queue .
|
Since 2.4
gint g_queue_index (GQueue *queue, gconstpointer data);
Returns the position of the first element in queue
which contains data
.
|
a GQueue |
|
the data to find. |
Returns : |
The position of the first element in queue which contains data , or -1 if no element in queue contains data .
|
Since 2.4
void g_queue_remove (GQueue *queue, gconstpointer data);
Removes the first element in queue
that contains data
.
|
a GQueue |
|
data to remove. |
Since 2.4
void g_queue_remove_all (GQueue *queue, gconstpointer data);
Remove all elements whose data equals data
from queue
.
|
a GQueue |
|
data to remove |
Since 2.4
void g_queue_insert_before (GQueue *queue, GList *sibling, gpointer data);
Inserts data
into queue
before sibling
.
sibling
must be part of queue
.
Since 2.4
void g_queue_insert_after (GQueue *queue, GList *sibling, gpointer data);
Inserts data
into queue
after sibling
sibling
must be part of queue
Since 2.4
void g_queue_insert_sorted (GQueue *queue, gpointer data, GCompareDataFunc func, gpointer user_data);
Inserts data
into queue
using func
to determine the new position.
|
a GQueue |
|
the data to insert |
|
the GCompareDataFunc used to compare elements in the queue. It is
called with two elements of the queue and user_data . It should
return 0 if the elements are equal, a negative value if the first
element comes before the second, and a positive value if the second
element comes before the first.
|
|
user data passed to func .
|
Since 2.4
void g_queue_push_head_link (GQueue *queue, GList *link_);
Adds a new element at the head of the queue.
void g_queue_push_tail_link (GQueue *queue, GList *link_);
Adds a new element at the tail of the queue.
void g_queue_push_nth_link (GQueue *queue, gint n, GList *link_);
Inserts link
into queue
at the given position.
|
a GQueue |
|
the position to insert the link. If this is negative or larger than
the number of elements in queue , the link is added to the end of
queue .
|
|
the link to add to queue
|
Since 2.4
GList* g_queue_pop_head_link (GQueue *queue);
Removes the first element of the queue.
GList* g_queue_pop_tail_link (GQueue *queue);
Removes the last element of the queue.
GList* g_queue_pop_nth_link (GQueue *queue, guint n);
Removes and returns the link at the given position.
|
a GQueue |
|
the link's position |
Returns : |
The n 'th link, or NULL if n is off the end of queue .
|
Since 2.4
GList* g_queue_peek_head_link (GQueue *queue);
Returns the first link in queue
Since 2.4
GList* g_queue_peek_tail_link (GQueue *queue);
Returns the last link queue
.
Since 2.4
GList* g_queue_peek_nth_link (GQueue *queue, guint n);
Returns the link at the given position
|
a GQueue |
|
the position of the link |
Returns : |
The link at the n 'th position, or NULL if n is off the
end of the list
|
Since 2.4
gint g_queue_link_index (GQueue *queue, GList *link_);
Returns the position of link_
in queue
.
|
a Gqueue |
|
A GList link |
Returns : |
The position of link_ , or -1 if the link is
not part of queue
|
Since 2.4
void g_queue_unlink (GQueue *queue, GList *link_);
Unlinks link_
so that it will no longer be part of queue
. The link is
not freed.
link_
must be part of queue
,
Since 2.4