deps/kb_meme/meme-5.0.1/src/array-list.c
/*
 * arraylst_put_n
 * The passed item is put at the passed index the passed
 * number of times. The index must be from 0 to the size
 * of the list inclusive or the opperation will die.
 */
arraylst_put_n
The passed item is put at the passed index the passed
number of times. The index must be from 0 to the size
of the list inclusive or the opperation will die.
arraylst_put_n The passed item is put at the passed index the passed number of times . The index must be from 0 to the size of the list inclusive or the opperation will die .
void arraylst_put_n(int times, int index, void *item, ARRAYLST_T *arraylst) {
  if (arraylst == NULL) { die("arraylst_put_n: arraylst is null!\n"); }
  if (index < 0 || index > arraylst->size) { die("arraylst_put_n: index must be between zero and size inclusive.\n"); }
  if (times < 0) { die("arraylst_put_n: times must be larger or equal to zero.\n"); }
  else if (times == 0) { return; }
  int new_size = arraylst->size + times;
  if (new_size > arraylst->cur_alloc) {
    int alloc = max(arraylst->cur_alloc, 1);
    do {
      alloc *= 2;
    } while (alloc < new_size);
    if (arraylst->cur_alloc == 0) {
      arraylst->array = mm_malloc(sizeof(void*)*alloc);
    } else {
      arraylst->array = mm_realloc(arraylst->array, sizeof(void*)*alloc);
    }
    arraylst->cur_alloc = alloc;
  }
  if (index < arraylst->size) {
    memmove(arraylst->array+(index+times), arraylst->array+(index), sizeof(void*)*(arraylst->size - index));
  }
  int i;
  for (i = 0; i < times; ++i) {
    arraylst->array[index + i] = item;
  }
  arraylst->size = new_size;
}
void arraylst_put_n ( int times , int index , void * item , ARRAYLST_T * arraylst ) { if ( arraylst == NULL ) { die ( " \n " ) ; } if ( index < 0 || index > arraylst -> size ) { die ( " \n " ) ; } if ( times < 0 ) { die ( " \n " ) ; } else if ( times == 0 ) { return ; } int new_size = arraylst -> size + times ; if ( new_size > arraylst -> cur_alloc ) { int alloc = max ( arraylst -> cur_alloc , 1 ) ; do { alloc *= 2 ; } while ( alloc < new_size ) ; if ( arraylst -> cur_alloc == 0 ) { arraylst -> array = mm_malloc ( sizeof ( void * ) * alloc ) ; } else { arraylst -> array = mm_realloc ( arraylst -> array , sizeof ( void * ) * alloc ) ; } arraylst -> cur_alloc = alloc ; } if ( index < arraylst -> size ) { memmove ( arraylst -> array + ( index + times ) , arraylst -> array + ( index ) , sizeof ( void * ) * ( arraylst -> size - index ) ) ; } int i ; for ( i = 0 ; i < times ; ++ i ) { arraylst -> array [ index + i ] = item ; } arraylst -> size = new_size ; }
arraylst_put_n
 The passed item is put at the passed index the passed
 number of times.
arraylst_put_n The passed item is put at the passed index the passed number of times .
//test parameters //ensure we have enough space //move anything in the way //set the item