--- libaitio/src/Attic/sarray.c 2011/06/07 11:49:39 1.3 +++ libaitio/src/Attic/sarray.c 2011/08/26 12:51:01 1.3.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: sarray.c,v 1.3 2011/06/07 11:49:39 misho Exp $ +* $Id: sarray.c,v 1.3.2.2 2011/08/26 12:51:01 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -90,8 +90,8 @@ io_sarrDestroy(sarr_t ** __restrict parr) { register int i; - assert(parr); - if (!parr) + assert(parr && *parr); + if (!parr || !*parr) return; for (i = 0; i < (*parr)->sarr_siz; i++) @@ -253,4 +253,48 @@ io_sarrSet(sarr_t * __restrict arr, u_int idx, void *d seg[pos] = data; return ret; +} + +/* + * io_sarr2array() - Convert from split-order array to dynamic array + * @sa = split array + * @sarrFree = after convert split array !=0 will be destroyed sarray + * return: NULL error or != NULL new array + */ +array_t * +io_sarr2array(sarr_t ** __restrict sa, int sarrFree) +{ + array_t *arr = NULL; + int el; + register int i; + + assert(sa && *sa); + if (!sa || !*sa) + return NULL; + + el = io_sarrSize(*sa); + arr = io_arrayInit(el); + if (!arr) + return NULL; + + for (i = 0; i < el; i++) + io_arraySet(arr, i, io_sarrGet(*sa, i + 1)); + + if (sarrFree) { + free(*sa); + *sa = NULL; + } + return arr; +} + +/* + * io_array2sarr() - Convert from dynamic array to split-order array + * @a = array + * @arrFree = after convert array !=0 will be destroyed + * return: NULL error or != NULL new sarr + */ +sarr_t * +io_array2sarr(array_t ** __restrict a, int arrFree) +{ + return NULL; }