*
* void darray_append(darray(T) arr, T item);
* void darray_prepend(darray(T) arr, T item);
+ * void darray_insert(darray(T) arr, size_t index, T item);
* void darray_push(darray(T) arr, T item); // same as darray_append
*
* Insertion (multiple items):
memmove((arr).item+1, (arr).item, ((arr).size-1)*sizeof(*(arr).item)); \
(arr).item[0] = (__VA_ARGS__); \
} while(0)
+#define darray_insert(arr, index, ...) do { \
+ size_t __index = index; \
+ darray_resize(arr, (arr).size+1); \
+ memmove((arr).item+__index+1, (arr).item+__index, ((arr).size-__index-1)*sizeof(*(arr).item)); \
+ (arr).item[__index] = (__VA_ARGS__); \
+ } while(0)
#define darray_push(arr, ...) darray_append(arr, __VA_ARGS__)
trace("Generating amalgams (internal)");
generateAmalgams();
- plan_tests(41);
+ plan_tests(47);
testLits();
ok1(darray_size(arr) == 0);
}
reset(arr);
-
+
+ testing(darray_insert);
+ {
+ size_t middle_i;
+
+ for (i=0; i < ARRAY_SIZE(lotsOfNumbers); i++)
+ darray_insert(arr, i, lotsOfNumbers[i]);
+ ok1(darray_size(arr) == ARRAY_SIZE(lotsOfNumbers));
+ ok1(darray_alloc(arr) >= darray_size(arr));
+ ok1(!memcmp(arr.item, lotsOfNumbers, sizeof(lotsOfNumbers)));
+
+ middle_i = ARRAY_SIZE(lotsOfNumbers) / 2;
+ darray_insert(arr, middle_i, 42);
+ ok1(darray_size(arr) == ARRAY_SIZE(lotsOfNumbers) + 1);
+ ok1(arr.item[middle_i] == 42);
+ ok1(arr.item[middle_i + 1] == lotsOfNumbers[middle_i]);
+ }
+ reset(arr);
+
testing(darray_from_c, darray_foreach, darray_foreach_reverse);
{
long *i;