Simple, generic list class.

Functions | |
| void | List_add (List_t *lst, void *item) |
| Adds item to the end of this List. | |
| unsigned int | List_countIf (const List_t *lst, ListItemPredicate predicate) |
| List_t * | List_create (void) |
| Creates a new List and returns a pointer to it. | |
| void * | List_find (const List_t *lst, const void *item1, ListItemComparator comparator) |
| List_t * | List_findIf (const List_t *lst, ListItemPredicate predicate) |
| void | List_free (List_t *lst) |
| Frees the given List. | |
| void * | List_get (const List_t *lst, unsigned int n) |
| Returns the nth item in this List. | |
| void | List_prepend (List_t *lst, void *item) |
| Adds item to the beginning of this List. | |
| void * | List_remove (List_t *lst, unsigned int n) |
| Removes the nth item from this List and returns a pointer to it. | |
| unsigned int | List_size (const List_t *lst) |
| ListNode_t * | ListNode_create (void *item) |
| Creates a new ListNode (with item) and returns a pointer to it. | |
| void | ListNode_free (ListNode_t *node) |
| Frees the given ListNode. | |
| unsigned int List_countIf | ( | const List_t * | lst, |
| ListItemPredicate | predicate | ||
| ) |
The typedef for ListItemPredicate is:
int (*ListItemPredicate) (const void *item);
where a return value of non-zero represents true and zero represents false.
| List_t* List_create | ( | void | ) |
Creates a new List and returns a pointer to it.
| void* List_find | ( | const List_t * | lst, |
| const void * | item1, | ||
| ListItemComparator | comparator | ||
| ) |
int (*ListItemComparator) (void *item1, void *item2);
The return value semantics are the same as for strcmp:
-1 item1 < item2, 0 item1 == item 2 1 item1 > item2
| List_t* List_findIf | ( | const List_t * | lst, |
| ListItemPredicate | predicate | ||
| ) |
The returned list may be empty.
The caller owns the returned list (but not its constituent items) and is responsible for freeing it with List_free().
| void List_free | ( | List_t * | lst | ) |
Frees the given List.
This function does not free List items. It frees only the List_t structure and its constituent ListNode_t structures (if any).
Presumably, you either i) have pointers to the individual list items elsewhere in your program and you want to keep them around for awhile longer or ii) the list has no items (List_size(lst) == 0). If neither are true, try List_freeItems() instead.
| void* List_get | ( | const List_t * | lst, |
| unsigned int | n | ||
| ) |
Returns the nth item in this List.
If n > List_size(lst) returns NULL.
| void List_prepend | ( | List_t * | lst, |
| void * | item | ||
| ) |
Adds item to the beginning of this List.
| void* List_remove | ( | List_t * | lst, |
| unsigned int | n | ||
| ) |
Removes the nth item from this List and returns a pointer to it.
If n > List_size(lst) returns NULL.
| ListNode_t* ListNode_create | ( | void * | item | ) |
Creates a new ListNode (with item) and returns a pointer to it.
| void ListNode_free | ( | ListNode_t * | node | ) |
Frees the given ListNode.