MCPcopy Create free account
hub / github.com/acl-dev/acl / array_pred_insert

Function array_pred_insert

lib_fiber/c/src/common/array.c:202–231  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200}
201
202int array_pred_insert(ARRAY *a, int position, void *obj)
203{
204 int idx;
205
206 /*
207 * a->items[count - 1] should be the last valid item node
208 * position should: positioin >= 0 && position <= a->count - 1
209 */
210 if(position < 0 || position >= a->count) {
211 return -1;
212 }
213
214 if(a->count >= a->capacity) {
215 array_grow(a, a->count + 1);
216 }
217
218 /* NOTICE: the C's index begin with 0
219 * when position == 0, just prepend one new node before the first node
220 * of the array
221 */
222 for(idx = a->count; idx > position && idx > 0; idx--) {
223 /* if idx == 0 then we has arrived
224 * at the beginning of the array
225 */
226 a->items[idx] = a->items[idx - 1];
227 }
228 a->items[position] = obj;
229 a->count++;
230 return position;
231}
232
233int array_succ_insert(ARRAY *a, int position, void *obj)
234{

Callers 1

array_prependFunction · 0.85

Calls 1

array_growFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…