Data Structures | |
| struct | _ListIterator |
| Definition of a ListIterator. More... | |
Defines | |
| #define | LIST_NULL ((void *) 0) |
| A null ListValue. | |
Typedefs | |
| typedef struct _ListEntry | ListEntry |
| Represents an entry in a doubly-linked list. | |
| typedef struct _ListIterator | ListIterator |
| Structure used to iterate over a list. | |
| typedef void * | ListValue |
| A value stored in a list. | |
| typedef int(* | ListCompareFunc )(ListValue value1, ListValue value2) |
| Callback function used to compare values in a list when sorting. | |
| typedef int(* | ListEqualFunc )(ListValue value1, ListValue value2) |
| Callback function used to determine of two values in a list are equal. | |
Functions | |
| void | list_free (ListEntry *list) |
| Free an entire list. | |
| ListEntry * | list_prepend (ListEntry **list, ListValue data) |
| Prepend a value to the start of a list. | |
| ListEntry * | list_append (ListEntry **list, ListValue data) |
| Append a value to the end of a list. | |
| ListEntry * | list_prev (ListEntry *listentry) |
| Retrieve the previous entry in a list. | |
| ListEntry * | list_next (ListEntry *listentry) |
| Retrieve the next entry in a list. | |
| ListValue | list_data (ListEntry *listentry) |
| Retrieve the value at a list entry. | |
| ListEntry * | list_nth_entry (ListEntry *list, int n) |
| Retrieve the entry at a specified index in a list. | |
| ListValue | list_nth_data (ListEntry *list, int n) |
| Retrieve the value at a specified index in the list. | |
| int | list_length (ListEntry *list) |
| Find the length of a list. | |
| ListValue * | list_to_array (ListEntry *list) |
| Create a C array containing the contents of a list. | |
| int | list_remove_entry (ListEntry **list, ListEntry *entry) |
| Remove an entry from a list. | |
| int | list_remove_data (ListEntry **list, ListEqualFunc callback, ListValue data) |
| Remove all occurrences of a particular value from a list. | |
| void | list_sort (ListEntry **list, ListCompareFunc compare_func) |
| Sort a list. | |
| ListEntry * | list_find_data (ListEntry *list, ListEqualFunc callback, ListValue data) |
| Find the entry for a particular value in a list. | |
| void | list_iterate (ListEntry **list, ListIterator *iter) |
| Initialise a ListIterator structure to iterate over a list. | |
| int | list_iter_has_more (ListIterator *iterator) |
| Determine if there are more values in the list to iterate over. | |
| ListValue | list_iter_next (ListIterator *iterator) |
| Using a list iterator, retrieve the next value from the list. | |
| void | list_iter_remove (ListIterator *iterator) |
| Delete the current entry in the list (the value last returned from list_iter_next). | |
A doubly-linked list stores a collection of values. Each entry in the list (represented by a pointer a ListEntry structure) contains a link to the next entry and the previous entry. It is therefore possible to iterate over entries in the list in either direction.
To create an empty list, create a new variable which is a pointer to a ListEntry structure, and initialise it to NULL. To destroy an entire list, use list_free.
To add a value to a list, use list_append or list_prepend.
To remove a value from a list, use list_remove_entry or list_remove_data.
To iterate over entries in a list, use list_iterate to initialise a ListIterator structure, with list_iter_next and list_iter_has_more to retrieve each value in turn. list_iter_remove can be used to remove the current entry.
To access an entry in the list by index, use list_nth_entry or list_nth_data.
To sort a list, use list_sort.
| typedef int(* ListCompareFunc)(ListValue value1, ListValue value2) |
Callback function used to compare values in a list when sorting.
| value1 | The first value to compare. | |
| value2 | The second value to compare. |
| typedef struct _ListEntry ListEntry |
Represents an entry in a doubly-linked list.
The empty list is represented by a NULL pointer. To initialise a new doubly linked list, simply create a variable of this type containing a pointer to NULL.
| typedef int(* ListEqualFunc)(ListValue value1, ListValue value2) |
Callback function used to determine of two values in a list are equal.
| value1 | The first value to compare. | |
| value2 | The second value to compare. |
Append a value to the end of a list.
| list | Pointer to the list to append to. | |
| data | The value to append. |
Retrieve the value at a list entry.
| listentry | Pointer to the list entry. |
| ListEntry* list_find_data | ( | ListEntry * | list, | |
| ListEqualFunc | callback, | |||
| ListValue | data | |||
| ) |
Find the entry for a particular value in a list.
| list | The list to search. | |
| callback | Function to invoke to compare values in the list with the value to be searched for. | |
| data | The value to search for. |
| void list_free | ( | ListEntry * | list | ) |
Free an entire list.
| list | The list to free. |
| int list_iter_has_more | ( | ListIterator * | iterator | ) |
Determine if there are more values in the list to iterate over.
| iterator | The list iterator. |
| ListValue list_iter_next | ( | ListIterator * | iterator | ) |
Using a list iterator, retrieve the next value from the list.
| iterator | The list iterator. |
| void list_iter_remove | ( | ListIterator * | iterator | ) |
Delete the current entry in the list (the value last returned from list_iter_next).
| iterator | The list iterator. |
| void list_iterate | ( | ListEntry ** | list, | |
| ListIterator * | iter | |||
| ) |
Initialise a ListIterator structure to iterate over a list.
| list | A pointer to the list to iterate over. | |
| iter | A pointer to an iterator structure to initialise. |
| int list_length | ( | ListEntry * | list | ) |
Find the length of a list.
| list | The list. |
Retrieve the next entry in a list.
| listentry | Pointer to the list entry. |
Retrieve the value at a specified index in the list.
| list | The list. | |
| n | The index into the list. |
Retrieve the entry at a specified index in a list.
| list | The list. | |
| n | The index into the list . |
Prepend a value to the start of a list.
| list | Pointer to the list to prepend to. | |
| data | The value to prepend. |
Retrieve the previous entry in a list.
| listentry | Pointer to the list entry. |
| int list_remove_data | ( | ListEntry ** | list, | |
| ListEqualFunc | callback, | |||
| ListValue | data | |||
| ) |
Remove all occurrences of a particular value from a list.
| list | Pointer to the list. | |
| callback | Function to invoke to compare values in the list with the value to be removed. | |
| data | The value to remove from the list. |
Remove an entry from a list.
| list | Pointer to the list. | |
| entry | The list entry to remove . |
| void list_sort | ( | ListEntry ** | list, | |
| ListCompareFunc | compare_func | |||
| ) |
Sort a list.
| list | Pointer to the list to sort. | |
| compare_func | Function used to compare values in the list. |
Create a C array containing the contents of a list.
| list | The list. |
1.5.5