5 #if defined(CVEC_MALLOC) && defined(CVEC_FREE) && defined(CVEC_REALLOC)
7 #elif !defined(CVEC_MALLOC) && !defined(CVEC_FREE) && !defined(CVEC_REALLOC)
10 #error "Must define all or none of CVEC_MALLOC, CVEC_FREE, and CVEC_REALLOC."
14 #define CVEC_MALLOC(sz) malloc(sz)
15 #define CVEC_REALLOC(p, sz) realloc(p, sz)
16 #define CVEC_FREE(p) free(p)
21 #define CVEC_MEMMOVE(dst, src, sz) memmove(dst, src, sz)
26 #define CVEC_ASSERT(x) assert(x)
31 #define CVEC_I_ALLOCATOR(x) ((x+1) * 2)
176 if (!(tmp = (
int*)
CVEC_REALLOC(vec->
a,
sizeof(
int)*tmp_sz))) {
184 vec->
a[vec->
size++] = a;
191 return vec->
a[--vec->
size];
197 return &vec->
a[vec->
size-1];
208 if (!(tmp = (
int*)
CVEC_REALLOC(vec->
a,
sizeof(
int)*tmp_sz))) {
230 if (!(tmp = (
int*)
CVEC_REALLOC(vec->
a,
sizeof(
int)*tmp_sz))) {
256 if (!(tmp = (
int*)
CVEC_REALLOC(vec->
a,
sizeof(
int)*tmp_sz))) {
312 if (size < vec->size) {
329 for (i=0; i<vec->
size; i++) {
#define CVEC_I_ALLOCATOR(x)
int cvec_insert_i(cvector_i *vec, cvec_sz i, int a)
Insert a at index i (0 based).
void cvec_free_i_heap(void *vec)
Frees everything so don't use vec after calling this.
void cvec_free_i(void *vec)
Frees the internal array and sets size and capacity to 0.
#define CVEC_REALLOC(p, sz)
int cvec_pop_i(cvector_i *vec)
Remove and return the last element (size decreased 1).
int cvec_copyc_i(void *dest, void *src)
Makes dest a copy of src.
int cvec_replace_i(cvector_i *vec, cvec_sz i, int a)
Replace value at index i with a, return original value.
int cvec_insert_array_i(cvector_i *vec, cvec_sz i, int *a, cvec_sz num)
Insert the first num elements of array a at index i.
cvector_i * cvec_init_i_heap(int *vals, cvec_sz num)
Create (on the heap) and initialize cvector_i with num elements of vals.
int cvec_copy_i(cvector_i *dest, cvector_i *src)
Makes dest a copy of src.
int cvec_set_cap_i(cvector_i *vec, cvec_sz size)
Set capacity to size.
#define CVEC_MEMMOVE(dst, src, sz)
int cvec_reserve_i(cvector_i *vec, cvec_sz size)
Make sure capacity is at least size(parameter not member).
int cvec_push_i(cvector_i *vec, int a)
Append a to end of vector (size increased 1).
void cvec_erase_i(cvector_i *vec, cvec_sz start, cvec_sz end)
Erases elements from start to end inclusive.
int cvec_init_i(cvector_i *vec, int *vals, cvec_sz num)
Same as cvec_init_i_heap() except the vector passed in was declared on the stack so it isn't allocate...
int cvec_i(cvector_i *vec, cvec_sz size, cvec_sz capacity)
Same as cvec_i_heap() except the vector passed in was declared on the stack so it isn't allocated in ...
cvector_i * cvec_i_heap(cvec_sz size, cvec_sz capacity)
Creates a new cvector_i on the heap.
int * cvec_back_i(cvector_i *vec)
Return pointer to last element.
void cvec_clear_i(cvector_i *vec)
Sets size to 0 (does not clear contents).
int cvec_extend_i(cvector_i *vec, cvec_sz num)
Increase the size of the array num items.
void cvec_set_val_cap_i(cvector_i *vec, int val)
Fills entire allocated array (capacity) with val.
void cvec_set_val_sz_i(cvector_i *vec, int val)
Set all size elements to val.
Data structure for int vector.
cvec_sz size
Current size (amount you use when manipulating array directly).
cvec_sz capacity
Allocated size of array; always >= size.