Reference manual

Dynlist was designed to be easy to use and as efficient as possible. Whenever a choice betweem these had to be made, efficiency would be the main focus. Because of this, there are many options to improve the way you use the library, specific to what you want to use it for. Following is a list of functions in the library, and how they work

Function overview

List manipulation

Item manipulation


#define dynlist(x, y) dynlist (x)=createlist(sizeof(y))
This macro function defines a dynlist object called x for items of type y (eg int)


dynlist createlist(int itemsize)
This function initializes and returns a dynlist object for items of size itemsize


void clearlist(dynlist *list)
This function frees all memory used by *list


void *compile(dynlist list)
This function "compiles" a list by converting it into a static array, after allocating sufficient space for it. A pointer to the array is returned.


dynlist decompile(void *data, int itemsize, int num)
This function "decompiles" a static array into a dynlist object. data specifies location of the array, itemsize the size of a single object in bytes, and num the amount of items in the array. The finished dynlist is passed as a return value


void catlists(dynlist *list1, dynlist *list2)
This function extends *list1 by *list2. If *list1 is empty, this function can be used to duplicate *list2. After using this function, *list2 still exists, so it should be cleaned up by clearlist() later


dynlist splitlist(dynlist *list, int i)
This function splits *list at i, and returns a new dynlist object containing anything from index i onward


long getsize(dynlist list)
This function returns the number of bytes used by list and all its items


long getlen(dynlist list)
This function returns the number of items in list (useful to initialize for loops)


void *newitem(dynlist *list)
This function allocates space for a new item in *list and returns a pointer to it


void additem(dynlist *list, void *item, int i)
This function adds a previously created item *item to *list at index i


void appenditem(dynlist *list, void *item)
This function is very similar to additem, except that *item is appended to the end of *list


void eraseitem(dynlist *list, int i)
This function erases the item at index i from *list


void *getitem(dynlist *list, int i)
This function returns a pointer to the item at index i in *list


void reverse(dynlist *list)
This function reverses the order of all items in *list


void swap(dynlist *list, int i, int j)

This function swaps the items at indices i and j


void sortlist(dynlist *list, int (*func)(void*, void*))

This function sorts *list based on the item comparison in *func (See the quick guide for details)