gslist.h File Reference

__G_SLIST_H__

Typedef GSList

typedef typedefG_BEGIN_DECLS struct _GSListGSList

g_slist_alloc ( void )

IMPORT_C GSList *g_slist_alloc(void)

g_slist_free ( GSList * )

IMPORT_C voidg_slist_free(GSList *list)

g_slist_free: : a GSList

Frees all of the memory used by a GSList. The freed elements are returned to the slice allocator.

g_slist_free_1 ( GSList * )

IMPORT_C voidg_slist_free_1(GSList *list)

g_slist_free_1: : a GSList element

Frees one GSList element. It is usually used after g_slist_remove_link().

g_slist_free1

g_slist_append ( GSList *, gpointer )

IMPORT_C GSList *g_slist_append(GSList *list,
gpointerdata
)

g_slist_append: : a GSList : the data for the new element

Adds a new element on to the end of the list.

<note>

The return value is the new start of the list, which may have changed, so make sure you store the new value.

</note>

<note>

Note that g_slist_append() has to traverse the entire list to find the end, which is inefficient when adding multiple elements. A common idiom to avoid the inefficiency is to prepend the elements and reverse the list when all elements have been added.

</note>

|[ / Notice that these are initialized to the empty list. / GSList *list = NULL, *number_list = NULL;

/ This is a list of strings. / list = g_slist_append (list, "first"); list = g_slist_append (list, "second");

/ This is a list of integers. / number_list = g_slist_append (number_list, GINT_TO_POINTER (27)); number_list = g_slist_append (number_list, GINT_TO_POINTER (14)); ]|

Returns: the new start of the GSList

g_slist_prepend ( GSList *, gpointer )

IMPORT_C GSList *g_slist_prepend(GSList *list,
gpointerdata
)

g_slist_prepend: : a GSList : the data for the new element

Adds a new element on to the start of the list.

<note>

The return value is the new start of the list, which may have changed, so make sure you store the new value.

</note>

|[ / Notice that it is initialized to the empty list. / GSList *list = NULL; list = g_slist_prepend (list, "last"); list = g_slist_prepend (list, "first"); ]|

Returns: the new start of the GSList

g_slist_insert ( GSList *, gpointer, gint )

IMPORT_C GSList *g_slist_insert(GSList *list,
gpointerdata,
gintposition
)

g_slist_insert: : a GSList : the data for the new element : the position to insert the element. If this is negative, or is larger than the number of elements in the list, the new element is added on to the end of the list.

Inserts a new element into the list at the given position.

Returns: the new start of the GSList

g_slist_insert_sorted ( GSList *, gpointer, GCompareFunc )

IMPORT_C GSList *g_slist_insert_sorted(GSList *list,
gpointerdata,
GCompareFuncfunc
)

g_slist_insert_sorted: : a GSList : the data for the new element : the function to compare elements in the list. It should return a number > 0 if the first parameter comes after the second parameter in the sort order.

Inserts a new element into the list, using the given comparison function to determine its position.

Returns: the new start of the GSList

g_slist_insert_sorted_with_data ( GSList *, gpointer, GCompareDataFunc, gpointer )

IMPORT_C GSList *g_slist_insert_sorted_with_data(GSList *list,
gpointerdata,
GCompareDataFuncfunc,
gpointeruser_data
)

g_slist_insert_sorted_with_data: : a GSList : the data for the new element : the function to compare elements in the list. It should return a number > 0 if the first parameter comes after the second parameter in the sort order. : data to pass to comparison function

Inserts a new element into the list, using the given comparison function to determine its position.

Returns: the new start of the GSList

Since: 2.10

g_slist_insert_before ( GSList *, GSList *, gpointer )

IMPORT_C GSList *g_slist_insert_before(GSList *slist,
GSList *sibling,
gpointerdata
)

g_slist_insert_before: : a GSList : node to insert before : data to put in the newly-inserted node

Inserts a node before containing .

Returns: the new head of the list.

g_slist_concat ( GSList *, GSList * )

IMPORT_C GSList *g_slist_concat(GSList *list1,
GSList *list2
)

g_slist_concat: : a GSList : the GSList to add to the end of the first GSList

Adds the second GSList onto the end of the first GSList. Note that the elements of the second GSList are not copied. They are used directly.

Returns: the start of the new GSList

g_slist_remove ( GSList *, gconstpointer )

IMPORT_C GSList *g_slist_remove(GSList *list,
gconstpointerdata
)

g_slist_remove: : a GSList : the data of the element to remove

Removes an element from a GSList. If two elements contain the same data, only the first is removed. If none of the elements contain the data, the GSList is unchanged.

Returns: the new start of the GSList

g_slist_remove_all ( GSList *, gconstpointer )

IMPORT_C GSList *g_slist_remove_all(GSList *list,
gconstpointerdata
)

g_slist_remove_all: : a GSList : data to remove

Removes all list nodes with data equal to . Returns the new head of the list. Contrast with g_slist_remove() which removes only the first node matching the given data.

Returns: new head of

g_slist_remove_link ( GSList *, GSList * )

IMPORT_C GSList *g_slist_remove_link(GSList *list,
GSList *link_
)

g_slist_remove_link: : a GSList : an element in the GSList

Removes an element from a GSList, without freeing the element. The removed element's next link is set to NULL, so that it becomes a self-contained list with one element.

Returns: the new start of the GSList, without the element

g_slist_delete_link ( GSList *, GSList * )

IMPORT_C GSList *g_slist_delete_link(GSList *list,
GSList *link_
)

g_slist_delete_link: : a GSList : node to delete

Removes the node link_ from the list and frees it. Compare this to g_slist_remove_link() which removes the node without freeing it.

Returns: the new head of

g_slist_reverse ( GSList * )

IMPORT_C GSList *g_slist_reverse(GSList *list)

g_slist_reverse: : a GSList

Reverses a GSList.

Returns: the start of the reversed GSList

g_slist_copy ( GSList * )

IMPORT_C GSList *g_slist_copy(GSList *list)

g_slist_copy: : a GSList

Copies a GSList.

<note>

Note that this is a "shallow" copy. If the list elements consist of pointers to data, the pointers are copied but the actual data isn't.

</note>

Returns: a copy of

g_slist_nth ( GSList *, guint )

IMPORT_C GSList *g_slist_nth(GSList *list,
guintn
)

g_slist_nth: : a GSList : the position of the element, counting from 0

Gets the element at the given position in a GSList.

Returns: the element, or NULL if the position is off the end of the GSList

g_slist_find ( GSList *, gconstpointer )

IMPORT_C GSList *g_slist_find(GSList *list,
gconstpointerdata
)

g_slist_find: : a GSList : the element data to find

Finds the element in a GSList which contains the given data.

Returns: the found GSList element, or NULL if it is not found

g_slist_find_custom ( GSList *, gconstpointer, GCompareFunc )

IMPORT_C GSList *g_slist_find_custom(GSList *list,
gconstpointerdata,
GCompareFuncfunc
)

g_slist_find_custom: : a GSList : user data passed to the function : the function to call for each element. It should return 0 when the desired element is found

Finds an element in a GSList, using a supplied function to find the desired element. It iterates over the list, calling the given function which should return 0 when the desired element is found. The function takes two gconstpointer arguments, the GSList element's data as the first argument and the given user data.

Returns: the found GSList element, or NULL if it is not found

g_slist_position ( GSList *, GSList * )

IMPORT_C gintg_slist_position(GSList *list,
GSList *llink
)

g_slist_position: : a GSList : an element in the GSList

Gets the position of the given element in the GSList (starting from 0).

Returns: the position of the element in the GSList, or -1 if the element is not found

g_slist_index ( GSList *, gconstpointer )

IMPORT_C gintg_slist_index(GSList *list,
gconstpointerdata
)

g_slist_index: : a GSList : the data to find

Gets the position of the element containing the given data (starting from 0).

Returns: the index of the element containing the data, or -1 if the data is not found

g_slist_last ( GSList * )

IMPORT_C GSList *g_slist_last(GSList *list)

g_slist_last: : a GSList

Gets the last element in a GSList.

<note>

This function iterates over the whole list.

</note>

Returns: the last element in the GSList, or NULL if the GSList has no elements

g_slist_length ( GSList * )

IMPORT_C guintg_slist_length(GSList *list)

g_slist_length: : a GSList

Gets the number of elements in a GSList.

<note>

This function iterates over the whole list to count its elements.

</note>

Returns: the number of elements in the GSList

g_slist_foreach ( GSList *, GFunc, gpointer )

IMPORT_C voidg_slist_foreach(GSList *list,
GFuncfunc,
gpointeruser_data
)

g_slist_foreach: : a GSList : the function to call with each element's data : user data to pass to the function

Calls a function for each element of a GSList.

g_slist_sort ( GSList *, GCompareFunc )

IMPORT_C GSList *g_slist_sort(GSList *list,
GCompareFunccompare_func
)

g_slist_sort: : a GSList : the comparison function used to sort the GSList. This function is passed the data from 2 elements of the GSList and should return 0 if they are equal, a negative value if the first element comes before the second, or a positive value if the first element comes after the second.

Sorts a GSList using the given comparison function.

Returns: the start of the sorted GSList

g_slist_sort_with_data ( GSList *, GCompareDataFunc, gpointer )

IMPORT_C GSList *g_slist_sort_with_data(GSList *list,
GCompareDataFunccompare_func,
gpointeruser_data
)

g_slist_sort_with_data: : a GSList : comparison function : data to pass to comparison function

Like g_slist_sort(), but the sort function accepts a user data argument.

Returns: new head of the list

g_slist_nth_data ( GSList *, guint )

IMPORT_C gpointerg_slist_nth_data(GSList *list,
guintn
)

g_slist_nth_data: : a GSList : the position of the element

Gets the data of the element at the given position.

Returns: the element's data, or NULL if the position is off the end of the GSList

g_slist_next

g_slist_push_allocator ( gpointer )

IMPORT_C voidg_slist_push_allocator(gpointerdummy)

g_slist_pop_allocator ( void )

IMPORT_C voidg_slist_pop_allocator(void)