Ilist Module

This module contains functions for creating and managing an Ilist, which is a managed array of arbitrary elements of one type. These elements can be addresses or structures.

Header to include: ilist.h

The Ilist structure


Ilist *ilistNew(int dsize, int asize)
void ilistTruncate(Ilist *list, int size)
void ilistQuantum(Ilist *list, int size)
Ilist *ilistDup(Ilist *list)
void ilistDelete(Ilist *list)
void *ilistFirst(Ilist *list)
void *ilistNext(Ilist *list)
void *ilistLast(Ilist *list)
void *ilistItem(Ilist *list, int element)
int ilistSize(Ilist *list)
int ilistAppend(Ilist *list, void *data)
void ilistRemove(Ilist *list, int element)
int ilistSwap(Ilist *list, int e1, int e2)
int ilistPush(Ilist *list, void *data)
void *ilistPop(Ilist *list)
int ilistFloat(Ilist *list, int element)
int ilistInsert(Ilist *list, void *data, int element)
void ilistShift(Ilist *list, int start, int amount)

The Ilist structure is described by:

  typedef struct ilist_struct
  {
    void *data;        /* Pointer to data */
    int   dsize;       /* Size of data element in bytes */
    int   current;     /* Current item */
    int   size;        /* Number of items on list */
    int   store;       /* Number of items space allocated for */
    int   quantum;     /* Increment when allocating more space */
  }Ilist;

Ilist *ilistNew(int dsize, int asize)

Gets a new list with data size given by dsize, initial allocation by asize.  Returns NULL for error.

void ilistTruncate(Ilist *list, int size)

Limits the size of list to size

void ilistQuantum(Ilist *list, int size)

Sets the quantum for increasing the size of list when needed to size

Ilist *ilistDup(Ilist *list)

Returns a duplicate of list, or NULL for an error

void ilistDelete (Ilist *list)

Deletes list and frees all memory

void *ilistFirst(Ilist *list)

Returns a pointer to the first item from list, or NULL for an error or empty list.

void *ilistNext(Ilist *list)

Returns a pointer to the next item from list, or NULL at the end of the list

void *ilistLast(Ilist *list)

Returns a pointer to the last item from list, or NULL for an error or empty list.

void *ilistItem(Ilist *list, int element)

Returns a pointer to the item in list at the index given by element, or NULL for error.

int ilistSize(Ilist *list)

Returns size of list

int ilistAppend(Ilist *list, void *data)

Appends data to the end of list, where the argument should be a pointer to the item to be copied into the list. Returns 1 if memory error, but retains previous state.

void ilistRemove(Ilist *list, int element)

Removes the item at element from list

int ilistSwap(Ilist *list, int e1, int e2)

Swaps the two elements e1 and e2 on list; returns 1 if error

int ilistPush(Ilist *list, void *data)

Inserts the item pointed to by data on the front of list; returns 1 if error

void *ilistPop(Ilist *list)

Pops an item off the front of list and returns it; returns NULL if error. The item has been malloc'ed and must be freed

int ilistFloat(Ilist *list, int element)

Moves the item at element to the front of list; returns 1 if error

int ilistInsert(Ilist *list, void *data, int element)

Inserts an item pointed to by data into list at the position given by element; returns 1 if error

void ilistShift(Ilist *list, int start, int amount)

Shift all items in list from the point given by start to the end by amount.