Diff for /libelwix/src/array.c between versions 1.1.1.1.6.1 and 1.6

version 1.1.1.1.6.1, 2013/03/19 17:02:12 version 1.6, 2019/01/21 11:57:13
Line 12  terms: Line 12  terms:
 All of the documentation and software included in the ELWIX and AITNET  All of the documentation and software included in the ELWIX and AITNET
 Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>  Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org>
   
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013Copyright 2004 - 2019
         by Michael Pounov <misho@elwix.org>.  All rights reserved.          by Michael Pounov <misho@elwix.org>.  All rights reserved.
   
 Redistribution and use in source and binary forms, with or without  Redistribution and use in source and binary forms, with or without
Line 52  SUCH DAMAGE. Line 52  SUCH DAMAGE.
  * @numItems = Number of Items   * @numItems = Number of Items
  * return: NULL error, != NULL allocated memory for array   * return: NULL error, != NULL allocated memory for array
  */   */
inline array_t *array_t *
 array_Init(int numItems)  array_Init(int numItems)
 {  {
         array_t *arr = NULL;          array_t *arr = NULL;
Line 137  array_To(array_t * __restrict arr) Line 137  array_To(array_t * __restrict arr)
  * @arr = Array   * @arr = Array
  * return: none   * return: none
  */   */
inline voidvoid
 array_Free(array_t * __restrict arr)  array_Free(array_t * __restrict arr)
 {  {
         register int i;          register int i;
Line 160  array_Free(array_t * __restrict arr) Line 160  array_Free(array_t * __restrict arr)
  * @parr = Array   * @parr = Array
  * return: none   * return: none
  */   */
inline voidvoid
 array_Destroy(array_t ** __restrict parr)  array_Destroy(array_t ** __restrict parr)
 {  {
         if (!parr || !*parr)          if (!parr || !*parr)
Line 173  array_Destroy(array_t ** __restrict parr) Line 173  array_Destroy(array_t ** __restrict parr)
 }  }
   
 /*  /*
    * array_Reset() - Reset array to initial state
    *
    * @parr = Array
    * @purge = Purge data, if <>0 then will be free entire data memory
    * return: none
    */
   void
   array_Reset(array_t * __restrict arr, int purge)
   {
           if (!arr)
                   return;
   
           arr->arr_last = -1;
           arr->arr_num = 0;
   
           if (purge && arr->arr_data) {
                   e_free(arr->arr_data);
                   arr->arr_data = e_calloc(array_Size(arr), sizeof(intptr_t));
           }
   
           array_Zero(arr);
   }
   
   /*
  * array_Len() - Get last used element in dynamic array (array Length)   * array_Len() - Get last used element in dynamic array (array Length)
  *   *
  * @arr = Array   * @arr = Array
  * return: -1 empty or >-1 position of last used element   * return: -1 empty or >-1 position of last used element
  */   */
inline intint
 array_Len(array_t * __restrict arr)  array_Len(array_t * __restrict arr)
 {  {
         register int i;          register int i;
Line 319  array_Concat(array_t * __restrict dest, array_t * __re Line 343  array_Concat(array_t * __restrict dest, array_t * __re
 /*  /*
  * array_Copy() Copy source array to destination array   * array_Copy() Copy source array to destination array
  *   *
 * @dest = Destination array, after use free with io_arrayDestroy() * @dest = Destination array, after use free with array_Destroy()
  * @src = Source array   * @src = Source array
  * return: -1 error; >0 count of destination array   * return: -1 error; >0 count of destination array
  */   */
Line 347  array_Copy(array_t ** __restrict dest, array_t * __res Line 371  array_Copy(array_t ** __restrict dest, array_t * __res
  * @data = Element, if set NULL GET element at position or !=NULL PUT element at position   * @data = Element, if set NULL GET element at position or !=NULL PUT element at position
  * return: -1 error or !=-1 return 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)  array_Elem(array_t * __restrict arr, int n, void *data)
 {  {
         void *dat = NULL;          void *dat = NULL;
Line 373  array_Elem(array_t * __restrict arr, int n, void *data Line 397  array_Elem(array_t * __restrict arr, int n, void *data
  * @nogrow = Don't grow array if not enough space   * @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   * return: -1 not found empty position, array is full!, >-1 return position of stored element into array
  */   */
inline intint
 array_Push(array_t * __restrict arr, void *data, int nogrow)  array_Push(array_t * __restrict arr, void *data, int nogrow)
 {  {
         int ret = -1;          int ret = -1;
Line 387  array_Push(array_t * __restrict arr, void *data, int n Line 411  array_Push(array_t * __restrict arr, void *data, int n
         if (!nogrow && ret >= array_Size(arr) && array_Grow(arr, ret + 1, 0))          if (!nogrow && ret >= array_Size(arr) && array_Grow(arr, ret + 1, 0))
                 return -1;                  return -1;
   
        ret = arr->arr_last++;        ret = ++arr->arr_last;
        if (data)        arr->arr_data[arr->arr_last] = data;
                arr->arr_data[arr->arr_last] = data; 
   
         return ret;          return ret;
 }  }
Line 402  array_Push(array_t * __restrict arr, void *data, int n Line 425  array_Push(array_t * __restrict arr, void *data, int n
  * @nodel = Don't delete after Pop element   * @nodel = Don't delete after Pop element
  * return: -1 not found used position, array is empty!, >-1 return element position   * return: -1 not found used position, array is empty!, >-1 return element position
  */   */
inline intint
 array_Pop(array_t * __restrict arr, void ** __restrict data, int nodel)  array_Pop(array_t * __restrict arr, void ** __restrict data, int nodel)
 {  {
         int ret = -1;          int ret = -1;
Line 410  array_Pop(array_t * __restrict arr, void ** __restrict Line 433  array_Pop(array_t * __restrict arr, void ** __restrict
         if (!arr)          if (!arr)
                 return -1;                  return -1;
   
        ret = array_Last(arr);        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--;
         }
   
         if (data)  
                 *data = arr->arr_data[ret];  
         if (!nodel)  
                 arr->arr_data[arr->arr_last--] = NULL;  
   
         return ret;          return ret;
 }  }
   
 /*  /*
  * array_Args() Parse and make array from arguments ... (input string will be modified!!!    * array_Args() Parse and make array from arguments ... (input string will be modified!!! 
 *      and output array must be free with io_arrayDestroy() after use!) *      and output array must be free with array_Destroy() after use!)
  *   *
  * @psArgs = Input arguments line, after execute string is modified!!!   * @psArgs = Input arguments line, after execute string is modified!!!
  * @nargs = Maximum requested count of arguments from input string psArgs, if 0 all psArgs   * @nargs = Maximum requested count of arguments from input string psArgs, if 0 all psArgs

Removed from v.1.1.1.1.6.1  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>