linkedlist(3m)

NAME
linkedlist - a sigularly linked list

SYNOPSIS
struct linkedlist *linkedlist_new(unsigned int max_size);
void linkedlist_del(struct linkedlist *this, void (*free_data_fn)(void *));
void linkedlist_clear(struct linkedlist *this, void (*free_data_fn)(void *));

int linkedlist_add(struct linkedlist *this, void *data);
int linkedlist_insert(struct linkedlist *this, unsigned int idx, void *data);
int linkedlist_is_empty(const struct linkedlist *this);
unsigned int linkedlist_size(const struct linkedlist *this);
void *linkedlist_get(const struct linkedlist *this, unsigned int idx);
void *linkedlist_get_last(const struct linkedlist *this);
void linkedlist_iterate(struct linkedlist *this);
void *linkedlist_next(struct linkedlist *this);
void *linkedlist_remove(struct linkedlist *this, unsigned int idx);
void *linkedlist_remove_last(struct linkedlist *this);

DESCRIPTION
The linkedlist functions manipulate a sigularly linked list of data pointers.

new Create a new linkedlist object that accepts no more than max_size items. If max_size is zero the list will accept no more than MAX_INT items. A linkedlist object may be freed with linkedlist_del.

del frees the list and all associated resources.

clear
    clears the list of all data pointers. If the free_data_fn function is not NULL, it will be called for each data pointer in the list as an argument.

add appends a data pointer to the end of the list.

insert
    inserts a data pointer before the item at idx. Ifidxequals the size of the list, the data pointer will be appended to the list.

is_empty
    tests if the list is empty.

size
    returns the number of items in the list.

get retrieves an item from the list by index.

get_last
    retrieves the last data pointer in the list.

iterate
    initializes an internal cursor to the first item in the list.

next
    returns the next item in the list or a null pointer if the end of the list has been reached.

remove
    removes the data pointer at idx from the list.

remove_last
    removes the last data pointer in the list.

RETURNS

new a new linkedlist object. If memory for the linkedlist cannot be allocated a null pointer is returned and errno is set to ENOMEM.

add zero if the operation failed and non-zero otherwise.

insert
    zero if the operation failed and non-zero otherwise.

is_empty
    non-zero if the list is empty and zero otherwise.

get the data pointer being retrieved. If the specified idx was not valid, a null pointer is returned and errno is set appropriately.

get_last
    the data pointer or a null pointer if the list is empty.

remove
    the data pointer removed from the list.

remove_last
    the data pointer removed from the list.