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_D_ALLOCATOR(x) ((x+1) * 2)
177 if (!(tmp = (
double*)
CVEC_REALLOC(vec->
a,
sizeof(
double)*tmp_sz))) {
184 vec->
a[vec->
size++] = a;
191 return vec->
a[--vec->
size];
197 return &vec->
a[vec->
size-1];
208 if (!(tmp = (
double*)
CVEC_REALLOC(vec->
a,
sizeof(
double)*tmp_sz))) {
230 if (!(tmp = (
double*)
CVEC_REALLOC(vec->
a,
sizeof(
double)*tmp_sz))) {
256 if (!(tmp = (
double*)
CVEC_REALLOC(vec->
a,
sizeof(
double)*tmp_sz))) {
273 double tmp = vec->
a[i];
312 if (size < vec->size)
315 if (!(tmp = (
double*)
CVEC_REALLOC(vec->
a,
sizeof(
double)*size))) {
328 for(i=0; i<vec->
size; i++) {
cvector_d * cvec_d_heap(cvec_sz size, cvec_sz capacity)
Creates a new cvector_d on the heap.
int cvec_insert_array_d(cvector_d *vec, cvec_sz i, double *a, cvec_sz num)
Insert the first num elements of array a at index i.
int cvec_insert_d(cvector_d *vec, cvec_sz i, double a)
Insert a at index i (0 based).
void cvec_free_d(void *vec)
Frees the internal array and sets size and capacity to 0.
#define CVEC_REALLOC(p, sz)
void cvec_erase_d(cvector_d *vec, cvec_sz start, cvec_sz end)
Erases elements from start to end inclusive.
cvector_d * cvec_init_d_heap(double *vals, cvec_sz num)
Create (on the heap) and initialize cvector_d with num elements of vals.
void cvec_set_val_cap_d(cvector_d *vec, double val)
Fills entire allocated array (capacity) with val.
int cvec_copy_d(cvector_d *dest, cvector_d *src)
Makes dest a copy of src.
int cvec_reserve_d(cvector_d *vec, cvec_sz size)
Make sure capacity is at least size(parameter not member).
#define CVEC_MEMMOVE(dst, src, sz)
int cvec_extend_d(cvector_d *vec, cvec_sz num)
Increase the size of the array num items.
int cvec_copyc_d(void *dest, void *src)
Makes dest a copy of src.
double cvec_replace_d(cvector_d *vec, cvec_sz i, double a)
Replace value at index i with a, return original value.
void cvec_set_val_sz_d(cvector_d *vec, double val)
Set all size elements to val.
int cvec_d(cvector_d *vec, cvec_sz size, cvec_sz capacity)
Same as cvec_d_heap() except the vector passed in was declared on the stack so it isn't allocated in ...
int cvec_set_cap_d(cvector_d *vec, cvec_sz size)
Set capacity to size.
#define CVEC_D_ALLOCATOR(x)
double * cvec_back_d(cvector_d *vec)
Return pointer to last element.
int cvec_push_d(cvector_d *vec, double a)
Append a to end of vector (size increased 1).
void cvec_clear_d(cvector_d *vec)
Sets size to 0 (does not clear contents).
void cvec_free_d_heap(void *vec)
Frees everything so don't use vec after calling this.
int cvec_init_d(cvector_d *vec, double *vals, cvec_sz num)
Same as cvec_init_d_heap() except the vector passed in was declared on the stack so it isn't allocate...
double cvec_pop_d(cvector_d *vec)
Remove and return the last element (size decreased 1).
Data structure for double vector.
cvec_sz size
Current size (amount you use when manipulating array directly).
cvec_sz capacity
Allocated size of array; always >= size.