| 231 | } |
| 232 | |
| 233 | int 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 | |
| 267 | int array_prepend(ARRAY *a, void *obj) |
| 268 | { |
nothing calls this directly
no test coverage detected
searching dependent graphs…