Data Structures | Typedefs | Functions

list.h File Reference

#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.
listprepend (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.
listtl (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.
listrev (list *l)
 Reverse a list in place.
listappend (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

typedef void* data

A data type.

typedef struct list list

A singly-linked list.

typedef void* val

A type for values.


Function Documentation

list* append ( list l1,
list l2 
)

Catenate two lists in place.

Parameters:
l1a first list.
l2a second list.
Returns:
the catenation of l1 and l2 (l1, really).
val fold_left ( val(*)(val, data f,
val  init,
const list l 
)

Fold left.

Parameters:
fa pointer to a function of two arguments.
initan initial value.
la 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:
preda pointer to a predicate function.
la list.
void free_list ( bool  data,
list l 
)

Free a list.

Parameters:
dataa boolean telling whether to free the list contents.
la 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.
data hd ( const list l)

Return the first element of the list.

Parameters:
la list of length >= 1.
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:
proca pointer to a procedure on data elements.
la list.
unsigned int length ( const list l)

Return the length of a list.

Parameters:
la list.
Returns:
the length of the list.
void map ( data(*)(data f,
list l 
)

Apply in place a function on each element of a list.

Parameters:
fa pointer to a function on data elements.
la 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:
esome data value.
la list.
data nth ( unsigned int  n,
const list l 
)

Return the nth element of a list.

Parameters:
na natural number.
la list of length >= 1.
Returns:
the nth element if it exists.
Precondition:
Assertion failure if the list is of length < n.
list* prepend ( data  obj,
list l 
)

Prepend some data in front of a list---in place.

Parameters:
objsome data to add to the list.
la list; might be NULL for the empty list.
Returns:
the augmented list.
list* rev ( list l)

Reverse a list in place.

Parameters:
lthe list to reverse.
Returns:
the reversed list.
Postcondition:
l now points to the end of the list.
list* tl ( list l)

Return the tail of the list in place.

Parameters:
la list of length >= 1
Returns:
the tail if it exists.
Precondition:
Assertion failure if the list is empty.
Postcondition:
Frees the head of the list.