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

Function array_succ_insert

lib_fiber/c/src/common/array.c:233–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231}
232
233int array_succ_insert(ARRAY *a, int position, void *obj)
234{
235 int idx, position_succ;
236
237 /*
238 * a->items[count - 1] should be the last valid item node
239 * position should: position >= 0 && position <= a->count - 1
240 */
241 if (position < 0 || position >= a->count) {
242 return -1;
243 }
244
245 if (a->count >= a->capacity) {
246 array_grow(a, a->count + 1);
247 }
248
249 position_succ = position + 1;
250
251 /*
252 * position_succ should:
253 * position_succ > 0 (position >= 0 and position_succ = position + 1)
254 * and position_succ <= a->count (when position == a->count - 1,
255 * position == a->count, and just append one new node after the
256 * last node)
257 * NOTICE: the C's index begin with 0
258 */
259 for (idx = a->count; idx > position_succ; idx--) {
260 a->items[idx] = a->items[idx - 1];
261 }
262 a->items[position_succ] = obj;
263 a->count++;
264 return position_succ;
265}
266
267int array_prepend(ARRAY *a, void *obj)
268{

Callers

nothing calls this directly

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…