summaryrefslogtreecommitdiff
path: root/arr.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2021-02-09 14:38:59 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2021-02-09 14:38:59 -0500
commit0135ebfa879af50f19ddc1495a36be3c030a6326 (patch)
tree080d209c633adc52560839ef2381b4fd1959a752 /arr.c
parent7be42dc83ff694da2f1e66a59a14fe51d3e18fba (diff)
find + replace seems to be working
Diffstat (limited to 'arr.c')
-rw-r--r--arr.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/arr.c b/arr.c
index dea2760..0e545f7 100644
--- a/arr.c
+++ b/arr.c
@@ -157,6 +157,12 @@ static void arr_set_len_(void **arr, size_t member_size, size_t n) {
}
}
+static void arr_remove_(void *arr, size_t member_size, size_t index) {
+ ArrHeader *hdr = arr_hdr_(arr);
+ assert(index < hdr->len);
+ memmove((char *)arr + index * member_size, (char *)arr + (index+1) * member_size, (hdr->len - (index+1)) * member_size);
+ --hdr->len;
+}
#ifdef __cplusplus
#define arr_cast_typeof(a) (decltype(a))
@@ -183,6 +189,7 @@ static void arr_set_len_(void **arr, size_t member_size, size_t n) {
// the newly-added elements are zero-initialized.
#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) arr_remove_((a), sizeof *(a), (i))
#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)