ZEDA
1.6.18
|
Macros | |
#define | zArrayClass(array_t, cell_t) |
generate array class. More... | |
#define | zArraySize(a) (a)->size |
#define | zArrayBuf(a) (a)->buf |
#define | zArrayPosIsValid(a, p) ( (p) < zArraySize(a) && (p) >= 0 ) |
#define | zArrayElemSize(a) sizeof(*zArrayBuf(a)) |
#define | zArrayElemNC(a, i) ( &zArrayBuf(a)[i] ) |
#define | zArrayElem(a, i) ( zArrayPosIsValid(a,i) ? zArrayElemNC(a,i) : NULL ) |
#define | zArraySetElemNC(a, i, d) memcpy( zArrayElemNC(a,i), (d), zArrayElemSize(a) ) |
#define | zArraySetElem(a, i, d) ( zArrayPosIsValid(a,i) ? zArraySetElemNC(a,i,d) : NULL ) |
#define | zArrayHead(a) zArrayElemNC( a, zArraySize(a)-1 ) |
#define | zArrayNeck(a) zArrayElemNC( a, zArraySize(a)-2 ) |
#define | zArrayTail(a) zArrayElemNC( a, 0 ) |
#define | zArrayInit(arr) |
#define | zArrayAlloc(arr, type, n) |
allocate an array. More... | |
#define | zArrayFree(arr) |
free an array. More... | |
#define | zArrayFindName(arr, name, ptr) zNameFind( zArrayBuf(arr), zArraySize(arr), name, ptr ) |
#define | zArrayAdd(arr, type, dat) |
add a new cell to an array. More... | |
#define | zArrayInsert(arr, type, pos, dat) |
insert a new cell into an array. More... | |
#define | zArrayDelete(arr, type, pos) |
delete a cell from an array. More... | |
#define | zArrayAppend(arr, subarr, type) |
append an array to another. More... | |
#define | zArrayQuickSort(arr, cmp, priv) zQuickSort( (void*)zArrayBuf(arr), zArraySize(arr), zArrayElemSize(arr), cmp, priv ) |
quick sort for an array. More... | |
Functions | |
void | zQuickSort (void *array, size_t nmemb, size_t size, int(*cmp)(void *, void *, void *), void *priv) |
quick sort for a pointer array. More... | |
#define zArrayClass | ( | array_t, | |
cell_t | |||
) |
generate array class.
A macro zArrayClass() can generate a new array class, which consists of the size of the array and the pointer to the array buffer. array_t is the class name to be defined. cell_t is the class name of the data to be arrayed.
The size of the array is acquired by zArraySize(). The array head can be accessed by zArrayBuf(). Each element can be accessed by zArrayElem(). For a faster access to each element, zArrayElemNC() is also available, which does not check the specified location.
The array can be freed by calling zArrayFree().
zArraySetElem() is available in order to set each element, which works only if the specified location is valid. zArraySetElemNC() is also available, which provides a faster access to each element without checking the validity of specified location. For frequent accesses to the head, neck (one-cell-before-head) and tail, zArrayHead(), zArrayNeck() and zArrayTail() are available.
#define zArraySize | ( | a | ) | (a)->size |
#define zArrayBuf | ( | a | ) | (a)->buf |
#define zArrayPosIsValid | ( | a, | |
p | |||
) | ( (p) < zArraySize(a) && (p) >= 0 ) |
#define zArrayElemSize | ( | a | ) | sizeof(*zArrayBuf(a)) |
#define zArrayElemNC | ( | a, | |
i | |||
) | ( &zArrayBuf(a)[i] ) |
#define zArrayElem | ( | a, | |
i | |||
) | ( zArrayPosIsValid(a,i) ? zArrayElemNC(a,i) : NULL ) |
#define zArraySetElemNC | ( | a, | |
i, | |||
d | |||
) | memcpy( zArrayElemNC(a,i), (d), zArrayElemSize(a) ) |
#define zArraySetElem | ( | a, | |
i, | |||
d | |||
) | ( zArrayPosIsValid(a,i) ? zArraySetElemNC(a,i,d) : NULL ) |
#define zArrayHead | ( | a | ) | zArrayElemNC( a, zArraySize(a)-1 ) |
#define zArrayNeck | ( | a | ) | zArrayElemNC( a, zArraySize(a)-2 ) |
#define zArrayTail | ( | a | ) | zArrayElemNC( a, 0 ) |
#define zArrayInit | ( | arr | ) |
#define zArrayAlloc | ( | arr, | |
type, | |||
n | |||
) |
allocate an array.
arr | array class instance to be allocated. |
type | the data type of the array cells. |
n | the number of cells. |
#define zArrayFree | ( | arr | ) |
#define zArrayFindName | ( | arr, | |
name, | |||
ptr | |||
) | zNameFind( zArrayBuf(arr), zArraySize(arr), name, ptr ) |
zArrayFindName() is valid for an array of a named class.
#define zArrayAdd | ( | arr, | |
type, | |||
dat | |||
) |
add a new cell to an array.
zArrayAdd() adds a new cell pointed by dat to an array arr at the last, incrementing the size of arr. type is the data type of the cell.
#define zArrayInsert | ( | arr, | |
type, | |||
pos, | |||
dat | |||
) |
insert a new cell into an array.
zArrayInsert() inserts a new cell pointed by dat to in an array arr at the location specified by pos, incrementing the size of arr. type is the data type of the cell.
#define zArrayDelete | ( | arr, | |
type, | |||
pos | |||
) |
delete a cell from an array.
zArrayDelete() deletes a cell at the location specified by pos in an array arr at, decrementing the size of arr. type is the data type of the cell.
#define zArrayAppend | ( | arr, | |
subarr, | |||
type | |||
) |
append an array to another.
zArrayAppend() appends an array pointed by subarr to another array pointed by arr. type is the data type of the cell.
#define zArrayQuickSort | ( | arr, | |
cmp, | |||
priv | |||
) | zQuickSort( (void*)zArrayBuf(arr), zArraySize(arr), zArrayElemSize(arr), cmp, priv ) |
quick sort for an array.
zArrayQuickSort() is a macro which is a wrapper of zQuickSort() that sorts an array pointed by array based on the quick sort algorithm. cmp and priv have the same roles with those for zQuickSort().
void zQuickSort | ( | void * | array, |
size_t | nmemb, | ||
size_t | size, | ||
int(*)(void *, void *, void *) | cmp, | ||
void * | priv | ||
) |
quick sort for a pointer array.
zQuickSort() sorts an array pointed by array based on the quick sort algorithm. nmemb is the number of components of array, and size is the size of each component. The components of array will be sorted in ascending order according to the comparison function cmp. Namely, a factor 'a' in the array is put after another factor 'b' if cmp(a,b,priv) > 0, where priv is for programmer's utility.