summaryrefslogtreecommitdiff
path: root/arr.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-28 14:01:10 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-28 14:01:10 -0500
commit5662c988fa199d071fdfd9e9defd8e09a3486b0c (patch)
tree95cd9999fcd5e9a300093a6c11c9d6905e3a45a9 /arr.c
parent7089b92ff5606f1e9b934e2236b0295dcab922ae (diff)
tab moving working?
Diffstat (limited to 'arr.c')
-rw-r--r--arr.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/arr.c b/arr.c
index 4e37892..ae25a3c 100644
--- a/arr.c
+++ b/arr.c
@@ -195,6 +195,10 @@ static void *arr_remove_(void *arr, size_t member_size, size_t index) {
#define arr_qsort(a, cmp) qsort((a), arr_len(a), sizeof *(a), (cmp))
#define arr_remove_last(a) do { assert(a); if (--arr_hdr_(a)->len == 0) arr_free(a); } while (0)
#define arr_remove(a, i) (void)((a) = arr_remove_((a), sizeof *(a), (i)))
+#define arr_insert(a, i, x) do { u32 _index = (i); (a) = arr_cast_typeof(a) arr_grow1_((a), sizeof *(a)); \
+ if (a) { memmove((a) + _index + 1, (a) + _index, (arr_len(a) - _index) * sizeof *(a));\
+ (a)[_index] = x; \
+ ++arr_hdr_(a)->len; } } while (0)
#define arr_pop_last(a) ((a)[--arr_hdr_(a)->len])
#define arr_size_in_bytes(a) (arr_len(a) * sizeof *(a))
#define arr_lastp(a) ((a) ? &(a)[arr_len(a)-1] : NULL)