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); }
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; }
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; }
/* 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); }
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); }