Split arraddn into pointer and index return

This commit is contained in:
Andreas Molzer 2020-03-25 20:12:21 +01:00
parent e423b41e74
commit e485c7d353
1 changed files with 11 additions and 4 deletions

View File

@ -108,11 +108,16 @@ DOCUMENTATION
Inserts n uninitialized items into array a starting at a[p],
moving the rest of the array over.
arraddn:
T* arraddn(T* a, int n)
arraddnptr:
T* arraddnptr(T* a, int n)
Appends n uninitialized items onto array at the end.
Returns a pointer to the first uninitialized item added.
arraddnoff:
size_t arraddnoff(T* a, int n)
Appends n uninitialized items onto array at the end.
Returns the index of the first uninitialized item added.
arrdel:
void arrdel(T* a, int p);
Deletes the element at a[p], moving the rest of the array over.
@ -390,7 +395,8 @@ CREDITS
#define arrpush stbds_arrput
#define arrpop stbds_arrpop
#define arrfree stbds_arrfree
#define arraddn stbds_arraddn
#define arraddnptr stbds_arraddnptr
#define arraddnoff stbds_arraddnoff
#define arrsetlen stbds_arrsetlen
#define arrlast stbds_arrlast
#define arrins stbds_arrins
@ -522,7 +528,8 @@ extern void * stbds_shmode_func(size_t elemsize, int mode);
#define stbds_arrput(a,v) (stbds_arrmaybegrow(a,1), (a)[stbds_header(a)->length++] = (v))
#define stbds_arrpush stbds_arrput // synonym
#define stbds_arrpop(a) (stbds_header(a)->length--, (a)[stbds_header(a)->length])
#define stbds_arraddn(a,n) (stbds_arrmaybegrow(a,n), stbds_header(a)->length += (n), &(a)[stbds_header(a)->length-(n)])
#define stbds_arraddnptr(a,n) (stbds_arrmaybegrow(a,n), stbds_header(a)->length += (n), &(a)[stbds_header(a)->length-(n)])
#define stbds_arraddnoff(a,n) (stbds_arrmaybegrow(a,n), stbds_header(a)->length += (n), stbds_header(a)->length-(n))
#define stbds_arrlast(a) ((a)[stbds_header(a)->length-1])
#define stbds_arrfree(a) ((void) ((a) ? STBDS_FREE(NULL,stbds_header(a)) : (void)0), (a)=NULL)
#define stbds_arrdel(a,i) stbds_arrdeln(a,i,1)