Mapper  0.9.0
API documentation
Functions
array.c File Reference

(f662771 on 7 Mar 2013)

#include <stdlib.h>
#include <string.h>
#include "array.h"
Include dependency graph for array.c:

Functions

int array_init (PtrArray *array)
 Initializes a existing pointer array with an size of zero. More...
 
int array_clear (PtrArray *array)
 Removes all items from a pointer array and deallocates any storage associated with it. More...
 
u32 array_count (const PtrArray *array)
 Returns the number of items in this array. More...
 
void * array_get (const PtrArray *array, u32 index)
 Returns the pointer at a given position in the array. More...
 
void * array_set (PtrArray *array, u32 index, void *value)
 Sets the pointer at a given position in the array and returns the former pointer at that location. More...
 
void * array_remove (PtrArray *array, u32 index)
 Removes the value at the given index from the array and returns the former pointer at that location. More...
 
int array_remove_range (PtrArray *array, u32 start, u32 count)
 Removes a range of indexes from the array. More...
 
int array_add (PtrArray *array, void *value)
 Appends the given value to the end of the array. More...
 
int array_insert (PtrArray *array, u32 index, void *value)
 Inserts the given value at a certain position in the array. More...
 
int array_splice (PtrArray *array, u32 start, u32 delete, const void **data, u32 count)
 Combines a removal and insertion operation, replacing some subsection of the array with a sequence of values (possibly of a different size). More...
 
int array_splice_array (PtrArray *array, u32 start, u32 delete, const PtrArray *data, u32 pos, u32 count)
 This function is like array_splice, but copies the inserted pointers from a another array defined by pos and count. More...
 

Function Documentation

◆ array_add()

int array_add ( PtrArray array,
void *  value 
)

Appends the given value to the end of the array.

The array size is increased by one. Returns ARRAY_OK or ARRAY_OUT_OF_MEMORY.

◆ array_clear()

int array_clear ( PtrArray array)

Removes all items from a pointer array and deallocates any storage associated with it.

Always returns ARRAY_OK.

◆ array_count()

u32 array_count ( const PtrArray array)

Returns the number of items in this array.

◆ array_get()

void* array_get ( const PtrArray array,
u32  index 
)

Returns the pointer at a given position in the array.

If the index is out of bounds, a nullptr pointer is returned.

◆ array_init()

int array_init ( PtrArray array)

Initializes a existing pointer array with an size of zero.

Since the caller is responsible for allocating the array, this function always returns ARRAY_OK.

◆ array_insert()

int array_insert ( PtrArray array,
u32  index,
void *  value 
)

Inserts the given value at a certain position in the array.

The array size is increased by one. Returns ARRAY_OK, ARRAY_INDEX_OUT_OF_BOUNDS, or ARRAY_OUT_OF_MEMORY.

◆ array_remove()

void* array_remove ( PtrArray array,
u32  index 
)

Removes the value at the given index from the array and returns the former pointer at that location.

If the index is out of bounds, the array is unchanged and nullptr is returned. The caller is responsible for owning the previous pointer, and determining whether to free it.

◆ array_remove_range()

int array_remove_range ( PtrArray array,
u32  index,
u32  count 
)

Removes a range of indexes from the array.

If any boundary condition is violated or the count is negative, the array is unchanged and ARRAY_INDEX_OUT_OF_BOUNDS is returned. A count of 0 is allowed and always returns ARRAY_OK provided the index is in a valid range. The deleted pointers are not provided to the caller.

◆ array_set()

void* array_set ( PtrArray array,
u32  index,
void *  value 
)

Sets the pointer at a given position in the array and returns the former pointer at that location.

If the index is out of bounds, the provided pointer is not stored, and nullptr is returned. The caller is responsible for owning the previous pointer, and determining whether to free it.

◆ array_splice()

int array_splice ( PtrArray array,
u32  start,
u32  del,
const void **  data,
u32  count 
)

Combines a removal and insertion operation, replacing some subsection of the array with a sequence of values (possibly of a different size).

If any boundary condition is violated, or either the deletion or insertion count is negative, the array is unchanged and ARRAY_INDEX_OUT_OF_BOUNDS is returned. As in array_remove, counts of zero are allowed, so this function can serve to both insert and remove items from the array, but is more efficient when both operations must be done. The function will return ARRAY_OUT_OF_MEMORY if it is unable to allocate memory for a growing array, and ARRAY_OK if the change was successful.

◆ array_splice_array()

int array_splice_array ( PtrArray array,
u32  start,
u32  del,
const PtrArray data,
u32  pos,
u32  count 
)

This function is like array_splice, but copies the inserted pointers from a another array defined by pos and count.

The array defined in data is left unchanged.