#include <stdbool.h>
Go to the source code of this file.
Data Structures |
struct | list |
| A singly-linked list. More...
|
Typedefs |
typedef void * | data |
| A data type.
|
typedef struct list | list |
| A singly-linked list.
|
typedef void * | val |
| A type for values.
|
Functions |
void | free_list (bool data, list *l) |
| Free a list.
|
list * | prepend (data obj, list *l) |
| Prepend some data in front of a list---in place.
|
unsigned int | length (const list *l) |
| Return the length of a list.
|
data | hd (const list *l) |
| Return the first element of the list.
|
list * | tl (list *l) |
| Return the tail of the list in place.
|
data | nth (unsigned int n, const list *l) |
| Return the nth element of a list.
|
list * | rev (list *l) |
| Reverse a list in place.
|
list * | append (list *l1, list *l2) |
| Catenate two lists in place.
|
bool | mem (const data e, const list *l) |
| Tests whether an element is a member of a list.
|
void | map (data(*f)(data), list *l) |
| Apply in place a function on each element of a list.
|
val | fold_left (val(*f)(val, data), val init, const list *l) |
| Fold left.
|
void | iter (void(*proc)(data), const list *l) |
| Apply a function on each element of a list.
|
bool | for_all (bool(*pred)(data), const list *l) |
| Check that a predicate holds of all elements of a list.
|
Typedef Documentation
Function Documentation
Catenate two lists in place.
- Parameters:
-
l1 | a first list. |
l2 | a second list. |
- Returns:
- the catenation of l1 and l2 (l1, really).
Fold left.
- Parameters:
-
f | a pointer to a function of two arguments. |
init | an initial value. |
l | a list. |
- Returns:
- the folding of l by f.
bool for_all |
( |
bool(*)(data) |
pred, |
|
|
const list * |
l |
|
) |
| |
Check that a predicate holds of all elements of a list.
- Parameters:
-
pred | a pointer to a predicate function. |
l | a list. |
void free_list |
( |
bool |
data, |
|
|
list * |
l |
|
) |
| |
Free a list.
- Parameters:
-
data | a boolean telling whether to free the list contents. |
l | a list to free. |
- Postcondition:
- The memory used for the list is freed. If `data' is true, then the objects in the list are also freed.
Return the first element of the list.
- Parameters:
-
- Returns:
- a pointer to the first object.
- Precondition:
- Assertion failure if the list is empty.
void iter |
( |
void(*)(data) |
proc, |
|
|
const list * |
l |
|
) |
| |
Apply a function on each element of a list.
- Parameters:
-
proc | a pointer to a procedure on data elements. |
l | a list. |
unsigned int length |
( |
const list * |
l | ) |
|
Return the length of a list.
- Parameters:
-
- Returns:
- the length of the list.
Apply in place a function on each element of a list.
- Parameters:
-
f | a pointer to a function on data elements. |
l | a list. |
- Postcondition:
- Each element e in the list is replaced by f(e).
bool mem |
( |
const data |
e, |
|
|
const list * |
l |
|
) |
| |
Tests whether an element is a member of a list.
- Parameters:
-
e | some data value. |
l | a list. |
data nth |
( |
unsigned int |
n, |
|
|
const list * |
l |
|
) |
| |
Return the nth element of a list.
- Parameters:
-
n | a natural number. |
l | a list of length >= 1. |
- Returns:
- the nth element if it exists.
- Precondition:
- Assertion failure if the list is of length < n.
Prepend some data in front of a list---in place.
- Parameters:
-
obj | some data to add to the list. |
l | a list; might be NULL for the empty list. |
- Returns:
- the augmented list.
Reverse a list in place.
- Parameters:
-
- Returns:
- the reversed list.
- Postcondition:
- l now points to the end of the list.
Return the tail of the list in place.
- Parameters:
-
- Returns:
- the tail if it exists.
- Precondition:
- Assertion failure if the list is empty.
- Postcondition:
- Frees the head of the list.