universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: ucx: /home/mike/workspace/c/ucx/src/ucx/list.h File Reference universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
ucx universe@390:
universe@390:
UAP Common Extensions
universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390:
universe@390: universe@390:
universe@390: universe@390: universe@390:
universe@390:
universe@390:
universe@390: Data Structures | universe@390: Macros | universe@390: Typedefs | universe@390: Functions
universe@390:
universe@390:
list.h File Reference
universe@390:
universe@390:
universe@390: universe@390:

Doubly linked list implementation. universe@390: More...

universe@390:
#include "ucx.h"
universe@390: #include "allocator.h"
universe@390:
universe@390:

Go to the source code of this file.

universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Data Structures

struct  UcxList
 UCX list structure. More...
 
universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Macros

#define UCX_FOREACH(elem, list)   for (UcxList* elem = (UcxList*) list ; elem != NULL ; elem = elem->next)
 Loop statement for UCX lists. More...
 
universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Typedefs

typedef struct UcxList UcxList
 UCX list type. More...
 
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:

universe@390: Functions

UcxListucx_list_clone (const UcxList *list, copy_func cpyfnc, void *data)
 Creates an element-wise copy of a list. More...
 
UcxListucx_list_clone_a (UcxAllocator *allocator, const UcxList *list, copy_func cpyfnc, void *data)
 Creates an element-wise copy of a list using a UcxAllocator. More...
 
int ucx_list_equals (const UcxList *list1, const UcxList *list2, cmp_func cmpfnc, void *data)
 Compares two UCX lists element-wise by using a compare function. More...
 
void ucx_list_free (UcxList *list)
 Destroys the entire list. More...
 
void ucx_list_free_a (UcxAllocator *allocator, UcxList *list)
 Destroys the entire list using a UcxAllocator. More...
 
void ucx_list_free_content (UcxList *list, ucx_destructor destr)
 Destroys the contents of the specified list by calling the specified destructor on each of them. More...
 
UcxListucx_list_append (UcxList *list, void *data)
 Inserts an element at the end of the list. More...
 
UcxListucx_list_append_a (UcxAllocator *allocator, UcxList *list, void *data)
 Inserts an element at the end of the list using a UcxAllocator. More...
 
UcxListucx_list_prepend (UcxList *list, void *data)
 Inserts an element at the beginning of the list. More...
 
UcxListucx_list_prepend_a (UcxAllocator *allocator, UcxList *list, void *data)
 Inserts an element at the beginning of the list using a UcxAllocator. More...
 
UcxListucx_list_concat (UcxList *list1, UcxList *list2)
 Concatenates two lists. More...
 
UcxListucx_list_first (const UcxList *elem)
 Returns the first element of a list. More...
 
UcxListucx_list_last (const UcxList *elem)
 Returns the last element of a list. More...
 
UcxListucx_list_get (const UcxList *list, size_t index)
 Returns the list element at the specified index. More...
 
ssize_t ucx_list_indexof (const UcxList *list, const UcxList *elem)
 Returns the index of an element. More...
 
size_t ucx_list_size (const UcxList *list)
 Returns the element count of the list. More...
 
ssize_t ucx_list_find (const UcxList *list, void *elem, cmp_func cmpfnc, void *data)
 Returns the index of an element containing the specified data. More...
 
int ucx_list_contains (const UcxList *list, void *elem, cmp_func cmpfnc, void *data)
 Checks, if a list contains a specific element. More...
 
UcxListucx_list_sort (UcxList *list, cmp_func cmpfnc, void *data)
 Sorts a UcxList with natural merge sort. More...
 
UcxListucx_list_remove (UcxList *list, UcxList *element)
 Removes an element from the list. More...
 
UcxListucx_list_remove_a (UcxAllocator *allocator, UcxList *list, UcxList *element)
 Removes an element from the list using a UcxAllocator. More...
 
UcxListucx_list_union (const UcxList *left, const UcxList *right, cmp_func cmpfnc, void *cmpdata, copy_func cpfnc, void *cpdata)
 Returns the union of two lists. More...
 
UcxListucx_list_union_a (UcxAllocator *allocator, const UcxList *left, const UcxList *right, cmp_func cmpfnc, void *cmpdata, copy_func cpfnc, void *cpdata)
 Returns the union of two lists. More...
 
UcxListucx_list_intersection (const UcxList *left, const UcxList *right, cmp_func cmpfnc, void *cmpdata, copy_func cpfnc, void *cpdata)
 Returns the intersection of two lists. More...
 
UcxListucx_list_intersection_a (UcxAllocator *allocator, const UcxList *left, const UcxList *right, cmp_func cmpfnc, void *cmpdata, copy_func cpfnc, void *cpdata)
 Returns the intersection of two lists. More...
 
UcxListucx_list_difference (const UcxList *left, const UcxList *right, cmp_func cmpfnc, void *cmpdata, copy_func cpfnc, void *cpdata)
 Returns the difference of two lists. More...
 
UcxListucx_list_difference_a (UcxAllocator *allocator, const UcxList *left, const UcxList *right, cmp_func cmpfnc, void *cmpdata, copy_func cpfnc, void *cpdata)
 Returns the difference of two lists. More...
 
universe@390:

Detailed Description

universe@390:

Doubly linked list implementation.

universe@390:
Author
Mike Becker
universe@390:
universe@390: Olaf Wintermann
universe@390:

Macro Definition Documentation

universe@390: universe@390:

◆ UCX_FOREACH

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
#define UCX_FOREACH( elem,
 list 
)   for (UcxList* elem = (UcxList*) list ; elem != NULL ; elem = elem->next)
universe@390:
universe@390: universe@390:

Loop statement for UCX lists.

universe@390:

The first argument is the name of the iteration variable. The scope of this variable is limited to the UCX_FOREACH statement.

universe@390:

The second argument is a pointer to the list. In most cases this will be the pointer to the first element of the list, but it may also be an arbitrary element of the list. The iteration will then start with that element.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
listThe first element of the list
elemThe variable name of the element
universe@390:
universe@390:
universe@390: universe@390:
universe@390:
universe@390:

Typedef Documentation

universe@390: universe@390:

◆ UcxList

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390:
typedef struct UcxList UcxList
universe@390:
universe@390: universe@390:

UCX list type.

universe@390:
See also
UcxList
universe@390: universe@390:
universe@390:
universe@390:

Function Documentation

universe@390: universe@390:

◆ ucx_list_append()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_append (UcxListlist,
void * data 
)
universe@390:
universe@390: universe@390:

Inserts an element at the end of the list.

universe@390:

This is generally an O(n) operation, as the end of the list is retrieved with ucx_list_last().

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
listthe list where to append the data, or NULL to create a new list
datathe data to insert
universe@390:
universe@390:
universe@390:
Returns
list, if it is not NULL or a pointer to the newly created list otherwise
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_append_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_append_a (UcxAllocatorallocator,
UcxListlist,
void * data 
)
universe@390:
universe@390: universe@390:

Inserts an element at the end of the list using a UcxAllocator.

universe@390:

See ucx_list_append() for details.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator to use
listthe list where to append the data, or NULL to create a new list
datathe data to insert
universe@390:
universe@390:
universe@390:
Returns
list, if it is not NULL or a pointer to the newly created list otherwise
universe@390:
See also
ucx_list_append()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_clone()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_clone (const UcxListlist,
copy_func cpyfnc,
void * data 
)
universe@390:
universe@390: universe@390:

Creates an element-wise copy of a list.

universe@390:

This function clones the specified list by creating new list elements and copying the data with the specified copy_func(). If no copy_func() is specified, a shallow copy is created and the new list will reference the same data as the source list.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
listthe list to copy
cpyfnca pointer to the function that shall copy an element (may be NULL)
dataadditional data for the copy_func()
universe@390:
universe@390:
universe@390:
Returns
a pointer to the copy
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_clone_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_clone_a (UcxAllocatorallocator,
const UcxListlist,
copy_func cpyfnc,
void * data 
)
universe@390:
universe@390: universe@390:

Creates an element-wise copy of a list using a UcxAllocator.

universe@390:

See ucx_list_clone() for details.

universe@390:

You might want to pass the allocator via the data parameter, to access it within the copy function for making deep copies.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator to use
listthe list to copy
cpyfnca pointer to the function that shall copy an element (may be NULL)
dataadditional data for the copy_func()
universe@390:
universe@390:
universe@390:
Returns
a pointer to the copy
universe@390:
See also
ucx_list_clone()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_concat()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_concat (UcxListlist1,
UcxListlist2 
)
universe@390:
universe@390: universe@390:

Concatenates two lists.

universe@390:

Either of the two arguments may be NULL.

universe@390:

This function modifies the references to the next/previous element of the last/first element of list1/ list2.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
list1first list
list2second list
universe@390:
universe@390:
universe@390:
Returns
if list1 is NULL, list2 is returned, otherwise list1 is returned
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_contains()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int ucx_list_contains (const UcxListlist,
void * elem,
cmp_func cmpfnc,
void * data 
)
universe@390:
universe@390: universe@390:

Checks, if a list contains a specific element.

universe@390:

An element is found, if ucx_list_find() returns a value greater than -1.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
listthe list where to search for the data
elemthe element data
cmpfncthe compare function
dataadditional data for the compare function
universe@390:
universe@390:
universe@390:
Returns
1, if and only if the list contains the specified element data
universe@390:
See also
ucx_list_find()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_difference()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_difference (const UcxListleft,
const UcxListright,
cmp_func cmpfnc,
void * cmpdata,
copy_func cpfnc,
void * cpdata 
)
universe@390:
universe@390: universe@390:

Returns the difference of two lists.

universe@390:

The difference contains all elements of the left list (including duplicates) that are not equal to any element of the right list.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
leftthe left source list
rightthe right source list
cmpfnca function to compare elements
cmpdataadditional data for the compare function
cpfnca function to copy the elements
cpdataadditional data for the copy function
universe@390:
universe@390:
universe@390:
Returns
a new list containing the difference
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_difference_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_difference_a (UcxAllocatorallocator,
const UcxListleft,
const UcxListright,
cmp_func cmpfnc,
void * cmpdata,
copy_func cpfnc,
void * cpdata 
)
universe@390:
universe@390: universe@390:

Returns the difference of two lists.

universe@390:

The difference contains all elements of the left list (including duplicates) that are not equal to any element of the right list.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorallocates the new list elements
leftthe left source list
rightthe right source list
cmpfnca function to compare elements
cmpdataadditional data for the compare function
cpfnca function to copy the elements
cpdataadditional data for the copy function
universe@390:
universe@390:
universe@390:
Returns
a new list containing the difference
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_equals()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
int ucx_list_equals (const UcxListlist1,
const UcxListlist2,
cmp_func cmpfnc,
void * data 
)
universe@390:
universe@390: universe@390:

Compares two UCX lists element-wise by using a compare function.

universe@390:

Each element of the two specified lists are compared by using the specified compare function and the additional data. The type and content of this additional data depends on the cmp_func() used.

universe@390:

If the list pointers denote elements within a list, the lists are compared starting with the denoted elements. Thus any previous elements are not taken into account. This might be useful to check, if certain list tails match each other.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
list1the first list
list2the second list
cmpfncthe compare function
dataadditional data for the compare function
universe@390:
universe@390:
universe@390:
Returns
1, if and only if the two lists equal element-wise, 0 otherwise
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_find()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
ssize_t ucx_list_find (const UcxListlist,
void * elem,
cmp_func cmpfnc,
void * data 
)
universe@390:
universe@390: universe@390:

Returns the index of an element containing the specified data.

universe@390:

This function uses a cmp_func() to compare the data of each list element with the specified data. If no cmp_func is provided, the pointers are compared.

universe@390:

If the list contains the data more than once, the index of the first occurrence is returned.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
listthe list where to search for the data
elemthe element data
cmpfncthe compare function
dataadditional data for the compare function
universe@390:
universe@390:
universe@390:
Returns
the index of the element containing the specified data or -1 if the data is not found in this list
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_first()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_first (const UcxListelem)
universe@390:
universe@390: universe@390:

Returns the first element of a list.

universe@390:

If the argument is the list pointer, it is directly returned. Otherwise this function traverses to the first element of the list and returns the list pointer.

universe@390:
Parameters
universe@390: universe@390: universe@390:
elemone element of the list
universe@390:
universe@390:
universe@390:
Returns
the first element of the list, the specified element is a member of
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_free()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
void ucx_list_free (UcxListlist)
universe@390:
universe@390: universe@390:

Destroys the entire list.

universe@390:

The members of the list are not automatically freed, so ensure they are otherwise referenced or destroyed by ucx_list_free_contents(). Otherwise, a memory leak is likely to occur.

universe@390:

Caution: the argument MUST denote an entire list (i.e. a call to ucx_list_first() on the argument must return the argument itself)

universe@390:
Parameters
universe@390: universe@390: universe@390:
listthe list to free
universe@390:
universe@390:
universe@390:
See also
ucx_list_free_contents()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_free_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
void ucx_list_free_a (UcxAllocatorallocator,
UcxListlist 
)
universe@390:
universe@390: universe@390:

Destroys the entire list using a UcxAllocator.

universe@390:

See ucx_list_free() for details.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator to use
listthe list to free
universe@390:
universe@390:
universe@390:
See also
ucx_list_free()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_free_content()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
void ucx_list_free_content (UcxListlist,
ucx_destructor destr 
)
universe@390:
universe@390: universe@390:

Destroys the contents of the specified list by calling the specified destructor on each of them.

universe@390:

Note, that the contents are not usable afterwards and the list should be destroyed with ucx_list_free().

universe@390:

If no destructor is specified (NULL), stdlib's free() is used.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
listthe list for which the contents shall be freed
destroptional destructor function
universe@390:
universe@390:
universe@390:
See also
ucx_list_free()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_get()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_get (const UcxListlist,
size_t index 
)
universe@390:
universe@390: universe@390:

Returns the list element at the specified index.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
listthe list to retrieve the element from
indexindex of the element to return
universe@390:
universe@390:
universe@390:
Returns
the element at the specified index or NULL, if the index is greater than the list size
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_indexof()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
ssize_t ucx_list_indexof (const UcxListlist,
const UcxListelem 
)
universe@390:
universe@390: universe@390:

Returns the index of an element.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
listthe list where to search for the element
elemthe element to find
universe@390:
universe@390:
universe@390:
Returns
the index of the element or -1 if the list does not contain the element
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_intersection()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_intersection (const UcxListleft,
const UcxListright,
cmp_func cmpfnc,
void * cmpdata,
copy_func cpfnc,
void * cpdata 
)
universe@390:
universe@390: universe@390:

Returns the intersection of two lists.

universe@390:

The intersection contains all elements of the left list (including duplicates) that can be found in the right list.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
leftthe left source list
rightthe right source list
cmpfnca function to compare elements
cmpdataadditional data for the compare function
cpfnca function to copy the elements
cpdataadditional data for the copy function
universe@390:
universe@390:
universe@390:
Returns
a new list containing the intersection
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_intersection_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_intersection_a (UcxAllocatorallocator,
const UcxListleft,
const UcxListright,
cmp_func cmpfnc,
void * cmpdata,
copy_func cpfnc,
void * cpdata 
)
universe@390:
universe@390: universe@390:

Returns the intersection of two lists.

universe@390:

The intersection contains all elements of the left list (including duplicates) that can be found in the right list.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorallocates the new list elements
leftthe left source list
rightthe right source list
cmpfnca function to compare elements
cmpdataadditional data for the compare function
cpfnca function to copy the elements
cpdataadditional data for the copy function
universe@390:
universe@390:
universe@390:
Returns
a new list containing the intersection
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_last()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_last (const UcxListelem)
universe@390:
universe@390: universe@390:

Returns the last element of a list.

universe@390:

If the argument has no successor, it is the last element and therefore directly returned. Otherwise this function traverses to the last element of the list and returns it.

universe@390:
Parameters
universe@390: universe@390: universe@390:
elemone element of the list
universe@390:
universe@390:
universe@390:
Returns
the last element of the list, the specified element is a member of
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_prepend()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_prepend (UcxListlist,
void * data 
)
universe@390:
universe@390: universe@390:

Inserts an element at the beginning of the list.

universe@390:

You should overwrite the old list pointer by calling mylist = ucx_list_prepend(mylist, mydata);. However, you may also perform successive calls of ucx_list_prepend() on the same list pointer, as this function always searchs for the head of the list with ucx_list_first().

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
listthe list where to insert the data or NULL to create a new list
datathe data to insert
universe@390:
universe@390:
universe@390:
Returns
a pointer to the new list head
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_prepend_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_prepend_a (UcxAllocatorallocator,
UcxListlist,
void * data 
)
universe@390:
universe@390: universe@390:

Inserts an element at the beginning of the list using a UcxAllocator.

universe@390:

See ucx_list_prepend() for details.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator to use
listthe list where to insert the data or NULL to create a new list
datathe data to insert
universe@390:
universe@390:
universe@390:
Returns
a pointer to the new list head
universe@390:
See also
ucx_list_prepend()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_remove()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_remove (UcxListlist,
UcxListelement 
)
universe@390:
universe@390: universe@390:

Removes an element from the list.

universe@390:

If the first element is removed, the list pointer changes. So it is highly recommended to always update the pointer by calling mylist = ucx_list_remove(mylist, myelem);.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390:
listthe list from which the element shall be removed
elementthe element to remove
universe@390:
universe@390:
universe@390:
Returns
returns the updated list pointer or NULL, if the list is now empty
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_remove_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_remove_a (UcxAllocatorallocator,
UcxListlist,
UcxListelement 
)
universe@390:
universe@390: universe@390:

Removes an element from the list using a UcxAllocator.

universe@390:

See ucx_list_remove() for details.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorthe allocator to use
listthe list from which the element shall be removed
elementthe element to remove
universe@390:
universe@390:
universe@390:
Returns
returns the updated list pointer or NULL, if the list
universe@390:
See also
ucx_list_remove()
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_size()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
size_t ucx_list_size (const UcxListlist)
universe@390:
universe@390: universe@390:

Returns the element count of the list.

universe@390:
Parameters
universe@390: universe@390: universe@390:
listthe list whose elements are counted
universe@390:
universe@390:
universe@390:
Returns
the element count
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_sort()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_sort (UcxListlist,
cmp_func cmpfnc,
void * data 
)
universe@390:
universe@390: universe@390:

Sorts a UcxList with natural merge sort.

universe@390:

This function uses O(n) additional temporary memory for merge operations that is automatically freed after each merge.

universe@390:

As the head of the list might change, you MUST call this function as follows: mylist = ucx_list_sort(mylist, mycmpfnc, mydata);.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390:
listthe list to sort
cmpfncthe function that shall be used to compare the element data
dataadditional data for the cmp_func()
universe@390:
universe@390:
universe@390:
Returns
the sorted list
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_union()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_union (const UcxListleft,
const UcxListright,
cmp_func cmpfnc,
void * cmpdata,
copy_func cpfnc,
void * cpdata 
)
universe@390:
universe@390: universe@390:

Returns the union of two lists.

universe@390:

The union is a list of unique elements regarding cmpfnc obtained from both source lists.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
leftthe left source list
rightthe right source list
cmpfnca function to compare elements
cmpdataadditional data for the compare function
cpfnca function to copy the elements
cpdataadditional data for the copy function
universe@390:
universe@390:
universe@390:
Returns
a new list containing the union
universe@390: universe@390:
universe@390:
universe@390: universe@390:

◆ ucx_list_union_a()

universe@390: universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
UcxList* ucx_list_union_a (UcxAllocatorallocator,
const UcxListleft,
const UcxListright,
cmp_func cmpfnc,
void * cmpdata,
copy_func cpfnc,
void * cpdata 
)
universe@390:
universe@390: universe@390:

Returns the union of two lists.

universe@390:

The union is a list of unique elements regarding cmpfnc obtained from both source lists.

universe@390:
Parameters
universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390: universe@390:
allocatorallocates the new list elements
leftthe left source list
rightthe right source list
cmpfnca function to compare elements
cmpdataadditional data for the compare function
cpfnca function to copy the elements
cpdataadditional data for the copy function
universe@390:
universe@390:
universe@390:
Returns
a new list containing the union
universe@390: universe@390:
universe@390:
universe@390:
universe@390: universe@390: universe@390: universe@390: