A doubly linked list data structure definition and functions.
s_list_new | Create a new list. |
s_list_delete | Delete a list. |
s_list_find_index | Find the element in the list which matches the comparison with the comparison function s_list_compare_fp. |
s_list_find | Find the list element which matches the given data with the comparison function s_list_compare_fp. |
s_list_index | Find the index into the list of the given list element. |
s_list_nth | Find the nth element in the list. |
s_list_first | Return the first element in the list. |
s_list_last | Return the last element in the list. |
s_list_element_get | Get the list element data. |
s_list_element_replace | Replace the list element data, does not delete old data. |
s_list_element_unlink | Unlink list element from list. |
s_list_element_delete | Remove the list element from it’s parent list and delete the list element data. |
s_list_element_next | Return the next element in the list relative to the given one. |
s_list_element_prev | Return the previous element in the list relative to the given one. |
s_list_isempty | Query if the list has any elements. |
s_list_size | Get the number of elements in the list. |
s_list_push | Push data onto end of list. |
s_list_pop | Pop last element of list. |
s_list_reverse | Reverse the elements in the list. |
s_list_prepend | Prepend data to beginning of the list. |
s_list_append | Append data to end of the list. |
s_list_insert_before | Insert data before given list element. |
s_list_insert_after | Insert data after given list element. |
Opaque definition of a doubly linked list.
The doubly linked list is headed by a pair of pointers, one to the head of the list and the other to the tail of the list. The elements are doubly linked so that an arbitrary element can be removed without a need to traverse the list. New elements can be added to the list before or after an existing element, at the head of the list, or at the end of the list. A doubly linked list may be traversed in either direction.
Opaque definition of a list element.
The list element represents one element in the doubly linked list.
Create a new list.
Creates a new list and sets the comparison and free functions. The comparison function must be of the type s_list_compare_fp while the free function must be of the type s_list_free_fp. If the comparison function is NULL then s_list_find will do nothing. If the free function is NULL then the s_list_element_delete and s_list_delete functions will do nothing.
Parameters: |
|
---|---|
Return: | Pointer to a list data structure. |
Delete a list.
Delete a list and all its elements. If the s_list_free_fp is NULL then the elements memory wont be freed.
Parameters: |
|
---|
The s_list element comparison function typedef.
A pointer to a function that compares 2 elements of a list.
Parameters: |
|
---|---|
Return: |
The s_list element free function typedef.
A pointer to a function that frees the dynamically allocated memory of a list element.
Parameters: |
|
---|
Find the element in the list which matches the comparison with the comparison function s_list_compare_fp.
If the comparison function is null then nothing is done.
Parameters: | |
---|---|
Return: | Pointer to the list element which matches the data, else NULL. |
Note: | Lists are indexed starting from 0. The index variable will be relative if f is notNULL. |
Find the list element which matches the given data with the comparison function s_list_compare_fp.
If the comparison function is NULL then nothing is done.
Parameters: |
|
---|---|
Return: | Pointer to the list element which matches the data, else NULL. |
Note: | Returns the first match. |
Find the index into the list of the given list element.
If the list comparison function s_list_compare_fp is NULL then nothing is done.
Parameters: |
|
---|---|
Return: | Pointer to the list element which matches the data, else NULL. |
Note: | Lists are indexed starting from 0. |
Find the nth element in the list.
Parameters: |
|
---|---|
Return: | Pointer to the nth list element or NULL if index is out of bounds. |
Note: | The list elements are indexed from 0. |
Return the first element in the list.
Parameters: |
|
---|---|
Return: | Pointer to the first element in the list. |
Return the last element in the list.
Parameters: |
|
---|---|
Return: | Pointer to the last element in the list. |
Get the list element data.
Parameters: |
|
---|---|
Return: | Pointer to the list element data. |
Replace the list element data, does not delete old data.
Parameters: |
|
---|---|
Return: | Pointer to the replaced list element data. |
Note: | The list element takes ownership of the new data. |
Unlink list element from list.
Does not delete data of element.
Parameters: |
|
---|---|
Return: | Pointer to the unlinked list element data. |
Note: | The caller is responsible for the returned data’s memory. |
Remove the list element from it’s parent list and delete the list element data.
Parameters: |
|
---|---|
Return: | Pointer to the previous list element or NULL if none. |
Note: | If s_list_free_fp is not defined then nothing is done and NULL returned. |
Return the next element in the list relative to the given one.
Parameters: |
|
---|---|
Return: | Pointer to the next element in the list. |
Return the previous element in the list relative to the given one.
Parameters: |
|
---|---|
Return: | Pointer to the previous element in the list. |
Push data onto end of list.
Same as s_list_append.
Parameters: |
|
---|---|
Note: | The list takes ownership of the data. |
Prepend data to beginning of the list.
Parameters: |
|
---|---|
Note: | The list takes ownership of the data. |
Append data to end of the list.
Parameters: |
|
---|---|
Note: | The list takes ownership of the data. |
Insert data before given list element.
Return reference to inserted data element.
Parameters: |
|
---|---|
Return: | Pointer to the inserted list element. |
Note: | The list takes ownership of the data. |
Insert data after given list element.
Return reference to inserted data element.
Parameters: |
|
---|---|
Return: | Pointer to the inserted list element. |
Note: | The list takes ownership of the data. |