--- libelwix/src/array.c 2013/01/17 10:05:35 1.1 +++ libelwix/src/array.c 2013/05/26 20:03:19 1.1.1.1.6.3 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: array.c,v 1.1 2013/01/17 10:05:35 misho Exp $ +* $Id: array.c,v 1.1.1.1.6.3 2013/05/26 20:03:19 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -52,7 +52,7 @@ SUCH DAMAGE. * @numItems = Number of Items * return: NULL error, != NULL allocated memory for array */ -inline array_t * +array_t * array_Init(int numItems) { array_t *arr = NULL; @@ -137,7 +137,7 @@ array_To(array_t * __restrict arr) * @arr = Array * return: none */ -inline void +void array_Free(array_t * __restrict arr) { register int i; @@ -160,7 +160,7 @@ array_Free(array_t * __restrict arr) * @parr = Array * return: none */ -inline void +void array_Destroy(array_t ** __restrict parr) { if (!parr || !*parr) @@ -178,7 +178,7 @@ array_Destroy(array_t ** __restrict parr) * @arr = Array * return: -1 empty or >-1 position of last used element */ -inline int +int array_Len(array_t * __restrict arr) { register int i; @@ -347,7 +347,7 @@ array_Copy(array_t ** __restrict dest, array_t * __res * @data = Element, if set NULL GET element at position or !=NULL PUT element at position * return: -1 error or !=-1 return element at position */ -inline void * +void * array_Elem(array_t * __restrict arr, int n, void *data) { void *dat = NULL; @@ -373,8 +373,8 @@ array_Elem(array_t * __restrict arr, int n, void *data * @nogrow = Don't grow array if not enough space * return: -1 not found empty position, array is full!, >-1 return position of stored element into array */ -inline int -array_Push(array_t * __restrict arr, void **data, int nogrow) +int +array_Push(array_t * __restrict arr, void *data, int nogrow) { int ret = -1; @@ -387,9 +387,8 @@ array_Push(array_t * __restrict arr, void **data, int if (!nogrow && ret >= array_Size(arr) && array_Grow(arr, ret + 1, 0)) return -1; - ret = arr->arr_last++; - if (data) - arr->arr_data[arr->arr_last] = *data; + ret = ++arr->arr_last; + arr->arr_data[arr->arr_last] = data; return ret; } @@ -402,7 +401,7 @@ array_Push(array_t * __restrict arr, void **data, int * @nodel = Don't delete after Pop element * return: -1 not found used position, array is empty!, >-1 return element position */ -inline int +int array_Pop(array_t * __restrict arr, void ** __restrict data, int nodel) { int ret = -1; @@ -410,12 +409,13 @@ array_Pop(array_t * __restrict arr, void ** __restrict if (!arr) return -1; - ret = array_Last(arr); - - if (data) - *data = arr->arr_data[ret]; - if (!nodel) - arr->arr_data[arr->arr_last--] = NULL; + if ((ret = array_Last(arr)) != -1) { + if (data) + *data = arr->arr_data[arr->arr_last]; + if (!nodel) + arr->arr_data[arr->arr_last] = NULL; + arr->arr_last--; + } return ret; }