|
int | arraylist_new (arraylist **l, arraylist_free_function *free_fn) |
|
int | arraylist_new_with_capacity (arraylist **l, size_t capacity, arraylist_free_function *free_fn) |
|
size_t | arraylist_length (arraylist *l) |
|
int | arraylist_insert (arraylist *l, size_t loc, void *item) |
|
int | arraylist_add (arraylist *l, void *item) |
|
int | arraylist_set (arraylist *l, size_t loc, void *item) |
|
void * | arraylist_get (arraylist *l, size_t loc) |
|
void | arraylist_clear (arraylist *l) |
|
int | arraylist_delete (arraylist *l, size_t loc) |
|
void | arraylist_free (arraylist *l) |
|
void | arraylist_print (arraylist *l, void(*item_print)(void *item)) |
|
ArrayList: This is a datastructure which implements the abstract datatype (ADT) list, using a fixed length array. The internal array is resized when it reaches capacity, and it's capacity is increased.
A list has the following operations:
- Insert/Put at location l 1.1 Push/Add at the end of the list
- Locate/Find item with value x
- Retrieve/Get value at location l
- Delete the value at location l
- Next - get the next location given location l
- Previous - get the previous location given location l (Next and Previous are trivial indexing operations in an arraylist)
- Makenull - empty the list
- First - gets the first location of the list (this is always 0 in an arraylist)
- PrintList - prints the list to the console/ to a string.
- Free - destructor/cleanup the list.
This struct represents the ArrayList and its pointer is the user's handle to the arraylist.
The values in the struct should be considered readonly, and should not be modified by user of the arraylist. User should always use the public methods of this implementation.
The capacity member of the struct shows the maximum number of items this arraylist can hold. This number should be carefully chosen at the time of creation of the arraylist.
The size holds the count of items currently in the list.
The array member is a pointer to an array of void pointers, each of which point to one value. Each value inserted in the array must be allocated by the caller and the function to free the items must be passed to the constructor.
int arraylist_insert |
( |
arraylist * |
l, |
|
|
size_t |
loc, |
|
|
void * |
item |
|
) |
| |
Insert item at location loc of the arraylist. Can insert at any location inclusive of 0 to length of array (that is one beyond the last element).
If loc is greater than current size, then returns E_ARRAYLIST_INDEX_NOT_FOUND. If the size of current arraylist has already reached MAX_VOIDPTR_ALLOCATE, then returns E_ARRAYLIST_INDEX_BEYOND_CAPACITY. If reallocation of arraylist to accomodate new item fails, then returns E_ARRAYLIST_UNABLE_TO_ALLOCATE_ARRAY.
- Parameters
-
l | the arraylist |
loc | location to insert at |
item | item to insert |
- Returns
- error code