deps/kb_meme/meme-5.0.1/src/array-list.c
/*
 * arraylst_remove_range
 * The items in the range are removed from the list and if a destructor is specified they are destroyed.
 * If a destructor is not specified the item that was at index is returned otherwise NULL is returned.
 */
arraylst_remove_range
The items in the range are removed from the list and if a destructor is specified they are destroyed.
If a destructor is not specified the item that was at index is returned otherwise NULL is returned.
arraylst_remove_range The items in the range are removed from the list and if a destructor is specified they are destroyed . If a destructor is not specified the item that was at index is returned otherwise NULL is returned .
void *arraylst_remove_range(int index, int count, void (*optional_item_destructor)(void*), ARRAYLST_T *arraylst) {
  void *item; 
  if (arraylst == NULL)                       die("arraylst_remove_range: arraylst is NULL!\n"); 
  if (count < 1)                              die("arraylst_remove_range: count must be one or more elements.\n"); 
  if (index < 0 || index >= arraylst->size)   die("arraylst_remove_range: index must be within bounds.\n");
  if(index + count > arraylst->size)          die("arraylst_remove_range: index + count is larger than size!\n");
  if (optional_item_destructor != NULL) {
    item = NULL;
    arraylst_apply_range(optional_item_destructor, index, count, arraylst);
  } else {
    item = arraylst->array[index];
  }
  if (index + count < arraylst->size) {
    memmove(arraylst->array+(index), arraylst->array+(index + count), sizeof(void*)*(arraylst->size - index - count));
  }
  arraylst->size -= count;
  if (arraylst->size < arraylst->cur_alloc / 4 && arraylst->min_alloc < arraylst->cur_alloc) {
    int alloc = max(arraylst->size * 2, arraylst->min_alloc);
    if (alloc == 0) {
      free(arraylst->array);
    } else {
      arraylst->array = (void**)mm_realloc(arraylst->array, sizeof(void*)*alloc);
    }
    arraylst->cur_alloc = alloc;
  }
  return item;
}
void * arraylst_remove_range ( int index , int count , void ( * optional_item_destructor ) ( void * ) , ARRAYLST_T * arraylst ) { void * item ; if ( arraylst == NULL ) die ( " \n " ) ; if ( count < 1 ) die ( " \n " ) ; if ( index < 0 || index >= arraylst -> size ) die ( " \n " ) ; if ( index + count > arraylst -> size ) die ( " \n " ) ; if ( optional_item_destructor != NULL ) { item = NULL ; arraylst_apply_range ( optional_item_destructor , index , count , arraylst ) ; } else { item = arraylst -> array [ index ] ; } if ( index + count < arraylst -> size ) { memmove ( arraylst -> array + ( index ) , arraylst -> array + ( index + count ) , sizeof ( void * ) * ( arraylst -> size - index - count ) ) ; } arraylst -> size -= count ; if ( arraylst -> size < arraylst -> cur_alloc / 4 && arraylst -> min_alloc < arraylst -> cur_alloc ) { int alloc = max ( arraylst -> size * 2 , arraylst -> min_alloc ) ; if ( alloc == 0 ) { free ( arraylst -> array ) ; } else { arraylst -> array = ( void * * ) mm_realloc ( arraylst -> array , sizeof ( void * ) * alloc ) ; } arraylst -> cur_alloc = alloc ; } return item ; }
arraylst_remove_range
 The items in the range are removed from the list and if a destructor is specified they are destroyed.
arraylst_remove_range The items in the range are removed from the list and if a destructor is specified they are destroyed .
// test parameters // destroy the items if we can // get the item to return // move the pointers after the removed range in to fill the deleted spot // update the size // shrink the array if the utilized portion drops to less than a quarter of the allocated size // unless we've already reached the minimum allowed allocation