예제 #1
0
파일: darray.c 프로젝트: NtsDK/liblcthw
int DArray_contract(DArray * array)
{
    int new_size = array->end < (int)array->expand_rate ? 
            (int)array->expand_rate : array->end;

    return DArray_resize(array, new_size + 1);
}
예제 #2
0
파일: darray.c 프로젝트: leondutoit/cstuff
int DArray_expand(DArray *array) {
    size_t old_max = array->max;
    check(DArray_resize(array, array->max + array->expand_rate) == 0,
        "failed to expand to new size: %d", array->max + (int)array->expand_rate);
    memset(array->contents + old_max, 0, array->expand_rate + 1);
    return 0;

error:
    return -1;
}
예제 #3
0
int DArray_expand(DArray *array) {
  size_t old_max = array->max;

  check(
      DArray_resize(array, array->max + array->expand_rate),
      "Failed to resize array to new size %d",
      array->max + (int)array->expand_rate
      );
  // look forward to the start of the new data (array->contents + old_max)
  // set all the data between there and the size of the new block to 0
  memset(array->contents + old_max, 0, array->expand_rate + 1);
  return 0;
error:
  return -1;
}
예제 #4
0
/* bring the array size down to max(array->end, array->expand_rate) */
int DArray_contract(DArray *array) {
  return DArray_resize(array, DArray_max(array->end, (int) array->expand_rate) + 1);
}
예제 #5
0
int DArray_contract(DArray *array) //always getting bigger
{
    int new_size = array->end < (int)array->expand_rate ? (int)array->expand_rate : array->end;
    
    return DArray_resize(array, new_size + 1);
}