Commit 26df9343 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Implement girara_list_sort

parent a478edba
......@@ -97,7 +97,7 @@ void girara_list_remove(girara_list_t* list, void* data)
list->start = g_list_delete_link(list->start, tmp);
}
void* girara_list_nth(girara_list_t* list, unsigned int n)
void* girara_list_nth(girara_list_t* list, size_t n)
{
g_return_val_if_fail(list, NULL);
g_return_val_if_fail(!list->start || (n < g_list_length(list->start)), NULL);
......@@ -223,6 +223,16 @@ girara_list_position(girara_list_t* list, void* data)
return -1;
}
void girara_list_sort(girara_list_t* list, girara_compare_function_t compare)
{
g_return_if_fail(list != NULL);
if (list->start == NULL) {
return;
}
list->start = g_list_sort(list->start, compare);
}
void
girara_list_foreach(girara_list_t* list, girara_list_callback_t callback, void* data)
{
......
......@@ -60,7 +60,7 @@ void girara_list_remove(girara_list_t* list, void* data);
* @param n Index of the entry
* @return The nth element or NULL if an error occured
*/
void* girara_list_nth(girara_list_t* list, unsigned int n);
void* girara_list_nth(girara_list_t* list, size_t n);
/**
* Checks if the list contains the given element
......@@ -88,6 +88,14 @@ size_t girara_list_size(girara_list_t* list);
*/
int girara_list_position(girara_list_t* list, void* data);
/**
* Sort a list
*
* @param list The list to sort
* @param compare compare function
*/
void girara_list_sort(girara_list_t* list, girara_compare_function_t compare);
/**
* Create an iterator pointing at the start of list.
*
......
......@@ -9,5 +9,6 @@ typedef struct girara_list_iterator_s girara_list_iterator_t;
typedef void (*girara_free_function_t)(void*);
typedef void (*girara_list_callback_t)(void*, void*);
typedef int (*girara_compare_function_t)(const void*, const void*);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment