libcmutils 0.6.5
Multi-platform C99 utility library
Loading...
Searching...
No Matches
CMUTIL_Array Struct Reference

Dynamic array of any type element. More...

Data Fields

CMBool(* Add )(CMUTIL_Array *array, void *item, void **ret)
 Add a new element to this array.
 
void *(* Remove )(CMUTIL_Array *array, const void *compval)
 Remove an item from this array.
 
void *(* InsertAt )(CMUTIL_Array *array, void *item, uint32_t index)
 Insert a new element to this array.
 
void *(* RemoveAt )(CMUTIL_Array *array, uint32_t index)
 Remove an item from this array.
 
void *(* SetAt )(CMUTIL_Array *array, void *item, uint32_t index)
 Replace an item at the position of this array.
 
void *(* GetAt )(const CMUTIL_Array *array, uint32_t index)
 Get an item from this array.
 
void *(* Find )(const CMUTIL_Array *array, const void *compval, uint32_t *index)
 Find an item from this array.
 
size_t(* GetSize )(const CMUTIL_Array *array)
 The size of this array.
 
CMBool(* Push )(CMUTIL_Array *array, void *item)
 Push an item to the end of this array like a stack operation.
 
void *(* Pop )(CMUTIL_Array *array)
 Pop an item from the end of this array like a stack operation.
 
void *(* Top )(const CMUTIL_Array *array)
 Get the top element from this array like a stack operation.
 
void *(* Bottom )(const CMUTIL_Array *array)
 Get the bottom element from this array like a stack operation.
 
CMUTIL_Iterator *(* Iterator )(const CMUTIL_Array *array)
 Get iterator of all items in this array.
 
void(* Clear )(CMUTIL_Array *array)
 Clear this array object.
 
void(* Destroy )(CMUTIL_Array *array)
 Destroy this array object.
 

Detailed Description

Dynamic array of any type element.

Field Documentation

◆ Add

CMBool(* CMUTIL_Array::Add) (CMUTIL_Array *array, void *item, void **ret)

Add a new element to this array.

If this array is a sorted array (created including comparator callback function), this method will add a new item to the appropriate location. Otherwise, this method will add a new item to the end of this array. If the freecb is supplied at the creation, this array will take the ownership of the item.

Parameters
arrayThis dynamic array object.
itemItem to be added.
retPointer to store the previous data at that position if this array is a sorted array. NULL if this is not a sorted array.
Returns
CMTrue if successful, CMFalse otherwise.

◆ Remove

void *(* CMUTIL_Array::Remove) (CMUTIL_Array *array, const void *compval)

Remove an item from this array.

This method will work both this array is sorted or not. But if this array is sorted, more efficient binary search will be used, otherwise linear search will be used. The compval will be compared with array elements in a binary search manner if this array is sorted. If this array is not sorted, the memory address will be compared to search the item. The ownership of the item will be moved to caller.

Parameters
arrayThis dynamic array object.
compvalSearch key of an item to be removed.
Returns
The removed element if given item found in this array. NULL if the given key does not exist in this array.

◆ InsertAt

void *(* CMUTIL_Array::InsertAt) (CMUTIL_Array *array, void *item, uint32_t index)

Insert a new element to this array.

This method will only work if this array is not a sorted array. New item will be stored at the given index. If the freecb is supplied at the creation, this array will take the ownership of the item.

Parameters
arrayThis dynamic array object.
itemItem to be inserted.
indexThe index of this array where the item will be stored in.
Returns
Inserted item if this array is not a sorted array. NULL if this array is a sorted array or the index is out of bound.

◆ RemoveAt

void *(* CMUTIL_Array::RemoveAt) (CMUTIL_Array *array, uint32_t index)

Remove an item from this array.

The item at the index of this array will be removed. The ownership of the item will be moved to caller.

Parameters
arrayThis dynamic array object.
indexThe index of this array which item will be removed.
Returns
The removed item. NULL if the index is out of bound.

◆ SetAt

void *(* CMUTIL_Array::SetAt) (CMUTIL_Array *array, void *item, uint32_t index)

Replace an item at the position of this array.

This method will only work if this array is not a sorted array. The item positioned at the index of this array will be replaced with the given item. If the freecb is supplied at the creation, this array will take the ownership of the item.

Parameters
arrayThis dynamic array object.
itemNew item which will replace the old one.
indexThe index of this array, the item in which will be replaced.
Returns
Replaced old item if this array is not a sorted array. NULL if this array is a sorted array or the index is out of bound.

◆ GetAt

void *(* CMUTIL_Array::GetAt) (const CMUTIL_Array *array, uint32_t index)

Get an item from this array.

Get an item which is stored at a given index. The ownership of the item does not be moved to the caller.

Parameters
arrayThis dynamic array object.
indexThe index of this array, the item in which will be retreived.
Returns
An item which positioned at index of this array. NULL if the given index is out of bound.

◆ Find

void *(* CMUTIL_Array::Find) (const CMUTIL_Array *array, const void *compval, uint32_t *index)

Find an item from this array.

This method will use binary search if this is a sorted array. Otherwise, linear search is used with memory address comparison. The ownership of the item does not be moved to the caller.

Parameters
arrayThis dynamic array object.
compvalSearch key of item which to be found.
indexThe index reference of the item which found with compval. Where the found item index will be stored in.
Returns
A found item from this array if the item found. NULL if the item is not found.

◆ GetSize

size_t(* CMUTIL_Array::GetSize) (const CMUTIL_Array *array)

The size of this array.

Parameters
arrayThis dynamic array object.
Returns
The size of this array.

◆ Push

CMBool(* CMUTIL_Array::Push) (CMUTIL_Array *array, void *item)

Push an item to the end of this array like a stack operation.

This method will only work if this array is not a sorted array. This operation will add the given item at the end of this array. If the freecb is supplied at the creation, this array will take the ownership of the item.

Parameters
arrayThis dynamic array object.
itemA new item to be pushed to this array.
Returns
CMTrue if push operation performed successfully. CMFalse otherwise.

◆ Pop

void *(* CMUTIL_Array::Pop) (CMUTIL_Array *array)

Pop an item from the end of this array like a stack operation.

This operation will remove an item at the end of this array. The ownership of the item will be moved to the caller.

Parameters
arrayThis dynamic array object.
Returns
Removed item if there are elements exists. NULL if there are no more elements.

◆ Top

void *(* CMUTIL_Array::Top) (const CMUTIL_Array *array)

Get the top element from this array like a stack operation.

Get the item at the end of this array. The ownership of the item does not be moved to the caller.

Parameters
arrayThis dynamic array object.
Returns
An item at the end of this array. NULL if there is no item in this array.

◆ Bottom

void *(* CMUTIL_Array::Bottom) (const CMUTIL_Array *array)

Get the bottom element from this array like a stack operation.

Get the item at the beginning of this array. The ownership of the item does not be moved to the caller.

Parameters
arrayThis dynamic array object.
Returns
An item at the beginning of this array. NULL if there is no item in this array.

◆ Iterator

CMUTIL_Iterator *(* CMUTIL_Array::Iterator) (const CMUTIL_Array *array)

Get iterator of all items in this array.

Parameters
arrayThis dynamic array object.
Returns
An CMUTIL_Iterator object of all items in this array.
See also
CMUTIL_Iterator

◆ Clear

void(* CMUTIL_Array::Clear) (CMUTIL_Array *array)

Clear this array object.

Clear all items in this array object and make its size to zero. If the freecb parameter is supplied at creation, this callback will be called to all items in this array.

Parameters
arrayThis dynamic array object.

◆ Destroy

void(* CMUTIL_Array::Destroy) (CMUTIL_Array *array)

Destroy this array object.

Destroy this object and its internal allocations. If the freecb parameter is supplied at creation, this callback will be called to all items in this array.

Parameters
arrayThis dynamic array object.

The documentation for this struct was generated from the following file: