version 1.4, 2011/08/29 12:00:57
|
version 1.5, 2011/10/31 13:53:51
|
Line 69 io_arrayInit(int numItems)
|
Line 69 io_arrayInit(int numItems)
|
free(arr); |
free(arr); |
return NULL; |
return NULL; |
} else |
} else |
memset(arr->arr_data, 0, io_arraySize(arr) * sizeof(void*)); | io_arrayZero(arr); |
|
|
return arr; |
return arr; |
} |
} |
Line 150 io_arrayFree(array_t * __restrict arr)
|
Line 150 io_arrayFree(array_t * __restrict arr)
|
{ |
{ |
register int i; |
register int i; |
|
|
assert(arr); |
|
if (!arr) |
if (!arr) |
return; |
return; |
|
|
Line 169 io_arrayFree(array_t * __restrict arr)
|
Line 168 io_arrayFree(array_t * __restrict arr)
|
inline void |
inline void |
io_arrayDestroy(array_t ** __restrict parr) |
io_arrayDestroy(array_t ** __restrict parr) |
{ |
{ |
assert(parr && *parr); |
|
if (!parr || !*parr) |
if (!parr || !*parr) |
return; |
return; |
|
|
Line 202 io_arrayLen(array_t * __restrict arr)
|
Line 200 io_arrayLen(array_t * __restrict arr)
|
* io_arrayGrow() - Grow/Shrink dynamic array, Use with care when it shrink!!! |
* io_arrayGrow() - Grow/Shrink dynamic array, Use with care when it shrink!!! |
* @arr = Array |
* @arr = Array |
* @newNumItems = Number of Items |
* @newNumItems = Number of Items |
|
* @freeShrink = Free elements before shrink array |
* return: -1 error, 0 ok |
* return: -1 error, 0 ok |
*/ |
*/ |
int |
int |
io_arrayGrow(array_t * __restrict arr, int newNumItems) | io_arrayGrow(array_t * __restrict arr, int newNumItems, int freeShrink) |
{ |
{ |
void **data; |
void **data; |
int n = 0; |
int n = 0; |
/* register int i; */ | register int i; |
|
|
assert(arr); |
|
if (!arr) |
if (!arr) |
return -1; |
return -1; |
|
|
Line 219 io_arrayGrow(array_t * __restrict arr, int newNumItems
|
Line 217 io_arrayGrow(array_t * __restrict arr, int newNumItems
|
return 0; |
return 0; |
if (io_arraySize(arr) < newNumItems) { |
if (io_arraySize(arr) < newNumItems) { |
n = newNumItems - io_arraySize(arr); |
n = newNumItems - io_arraySize(arr); |
} /* else | } else if (freeShrink) |
for (i = newNumItems; i < arr->arr_num; i++) |
for (i = newNumItems; i < arr->arr_num; i++) |
if (arr->arr_data[i]) |
if (arr->arr_data[i]) |
free(arr->arr_data[i]); |
free(arr->arr_data[i]); |
*/ |
|
|
|
arr->arr_num = newNumItems; |
arr->arr_num = newNumItems; |
if (io_arraySize(arr)) { |
if (io_arraySize(arr)) { |
Line 256 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
Line 253 io_arrayVacuum(array_t * __restrict arr, int fromWhere
|
register int i, j, num; |
register int i, j, num; |
int cx = 0; |
int cx = 0; |
|
|
assert(arr); |
|
if (!arr) |
if (!arr) |
return -1; |
return -1; |
else |
else |
Line 309 io_arrayPush(array_t * __restrict arr, void **data)
|
Line 305 io_arrayPush(array_t * __restrict arr, void **data)
|
register int i; |
register int i; |
int ret = -1; |
int ret = -1; |
|
|
assert(arr); |
|
|
|
for (i = 0; i < io_arraySize(arr); i++) |
for (i = 0; i < io_arraySize(arr); i++) |
if (!arr->arr_data[i]) { |
if (!arr->arr_data[i]) { |
if (data) |
if (data) |
Line 335 io_arrayPop(array_t * __restrict arr, void ** __restri
|
Line 329 io_arrayPop(array_t * __restrict arr, void ** __restri
|
register int i; |
register int i; |
int ret = -1; |
int ret = -1; |
|
|
assert(arr); |
|
|
|
for (i = io_arraySize(arr) - 1; i >= 0; i--) |
for (i = io_arraySize(arr) - 1; i >= 0; i--) |
if (arr->arr_data[i]) { |
if (arr->arr_data[i]) { |
if (data) |
if (data) |
Line 367 io_arrayConcat(array_t * __restrict dest, array_t * __
|
Line 359 io_arrayConcat(array_t * __restrict dest, array_t * __
|
return -1; |
return -1; |
|
|
n = io_arraySize(dest); |
n = io_arraySize(dest); |
if (io_arrayGrow(dest, n + io_arraySize(src))) | if (io_arrayGrow(dest, n + io_arraySize(src), 0)) |
return -1; |
return -1; |
memcpy(dest->arr_data + n, src->arr_data, io_arraySize(src) * sizeof(void*)); |
memcpy(dest->arr_data + n, src->arr_data, io_arraySize(src) * sizeof(void*)); |
|
|
return io_arraySize(dest); |
return io_arraySize(dest); |
|
} |
|
|
|
/* |
|
* io_arrayCopy() Copy source array to destination array |
|
* @dest = Destination array, after use free with io_arrayDestroy() |
|
* @src = Source array |
|
* return: -1 error; >0 count of destination array |
|
*/ |
|
int |
|
io_arrayCopy(array_t ** __restrict dest, array_t * __restrict src) |
|
{ |
|
assert(dest); |
|
assert(src); |
|
if (!dest || !src) |
|
return -1; |
|
|
|
*dest = io_arrayInit(io_arraySize(src)); |
|
if (!*dest) |
|
return -1; |
|
|
|
memcpy((*dest)->arr_data, src->arr_data, io_arraySize(*dest) * sizeof(void*)); |
|
return io_arraySize(*dest); |
} |
} |
|
|
/* |
/* |