deps/kb_meme/meme-5.0.1/src/array-list.c
/*
 * arraylst_preallocate
 * Ensures that space up to the passed size is avaliable so
 * that add operations won't cause unnecessary expansions. 
 * If this has been called than remove opperations won't 
 * cause a shrink smaller than this size until this method 
 * is called again or arraylst_fit is called.
 */
arraylst_preallocate
Ensures that space up to the passed size is avaliable so
that add operations won't cause unnecessary expansions.
If this has been called than remove opperations won't
cause a shrink smaller than this size until this method
is called again or arraylst_fit is called.
arraylst_preallocate Ensures that space up to the passed size is avaliable so that add operations won ' t cause unnecessary expansions . If this has been called than remove opperations won ' t cause a shrink smaller than this size until this method is called again or arraylst_fit is called .
void arraylst_preallocate(int size, ARRAYLST_T *arraylst) {
  if (arraylst == NULL) die("arraylst_preallocate: arraylst is null!\n");
  if (size < 0)         die("arraylst_preallocate: size is smaller than zero.\n");
  arraylst->min_alloc = size;
  if (arraylst->min_alloc > arraylst->cur_alloc) {
    if (arraylst->cur_alloc == 0) {
      arraylst->array = (void**)mm_malloc(sizeof(void*)*arraylst->min_alloc);
    } else {
      arraylst->array = (void**)mm_realloc(arraylst->array, sizeof(void*)*arraylst->min_alloc);
    }
    arraylst->cur_alloc = arraylst->min_alloc;
  } else if (arraylst->size < (arraylst->cur_alloc / 4) && arraylst->min_alloc < arraylst->cur_alloc) {
    int require = max(arraylst->size * 2, arraylst->min_alloc);
    if (require == 0) {
      free(arraylst->array);
    } else {
      arraylst->array = (void**)mm_realloc(arraylst->array, sizeof(void*)*require);
    }
    arraylst->cur_alloc = require;
  }
}
void arraylst_preallocate ( int size , ARRAYLST_T * arraylst ) { if ( arraylst == NULL ) die ( " \n " ) ; if ( size < 0 ) die ( " \n " ) ; arraylst -> min_alloc = size ; if ( arraylst -> min_alloc > arraylst -> cur_alloc ) { if ( arraylst -> cur_alloc == 0 ) { arraylst -> array = ( void * * ) mm_malloc ( sizeof ( void * ) * arraylst -> min_alloc ) ; } else { arraylst -> array = ( void * * ) mm_realloc ( arraylst -> array , sizeof ( void * ) * arraylst -> min_alloc ) ; } arraylst -> cur_alloc = arraylst -> min_alloc ; } else if ( arraylst -> size < ( arraylst -> cur_alloc / 4 ) && arraylst -> min_alloc < arraylst -> cur_alloc ) { int require = max ( arraylst -> size * 2 , arraylst -> min_alloc ) ; if ( require == 0 ) { free ( arraylst -> array ) ; } else { arraylst -> array = ( void * * ) mm_realloc ( arraylst -> array , sizeof ( void * ) * require ) ; } arraylst -> cur_alloc = require ; } }
arraylst_preallocate
 Ensures that space up to the passed size is avaliable so
 that add operations won't cause unnecessary expansions.
arraylst_preallocate Ensures that space up to the passed size is avaliable so that add operations won ' t cause unnecessary expansions .
//test parameters //expand //shrink