int zc_arraylist_set(zc_arraylist_t * a_list, int idx, void *data) { if (idx > a_list->size - 1) { if (zc_arraylist_expand_inner(a_list, idx)) { zc_error("expand_internal fail"); return -1; } } if (a_list->array[idx] && a_list->del) a_list->del(a_list->array[idx]); a_list->array[idx] = data; if (a_list->len <= idx) a_list->len = idx + 1; return 0; }
/* assum idx < len */ static int zc_arraylist_insert_inner(zc_arraylist_t * a_list, int idx, void *data) { if (a_list->array[idx] == NULL) { a_list->array[idx] = data; return 0; } if (a_list->len > a_list->size - 1) { if (zc_arraylist_expand_inner(a_list, 0)) { zc_error("expand_internal fail"); return -1; } } memmove(a_list->array + idx + 1, a_list->array + idx, (a_list->len - idx) * sizeof(void *)); a_list->array[idx] = data; a_list->len++; return 0; }