refactor: move dynarray into own module
This commit is contained in:
parent
e5f0ac8dec
commit
caee502382
7 changed files with 69 additions and 71 deletions
34
include/vieter_dynarray.h
Normal file
34
include/vieter_dynarray.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#ifndef VIETER_DYNARRAY
|
||||
#define VIETER_DYNARRAY
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
typedef struct vieter_dynarray {
|
||||
char **array;
|
||||
size_t capacity;
|
||||
size_t size;
|
||||
} vieter_dynarray;
|
||||
|
||||
/*
|
||||
* Allocate a dynamic array.
|
||||
*/
|
||||
vieter_dynarray *vieter_dynarray_init(size_t initial_capacity);
|
||||
|
||||
/*
|
||||
* Initialise array (if it's not already initialised) and insert a string.
|
||||
*/
|
||||
void vieter_dynarray_add(vieter_dynarray *da, const char *s);
|
||||
|
||||
/*
|
||||
* Deallocate dynamic array.
|
||||
*/
|
||||
void vieter_dynarray_free(vieter_dynarray *da);
|
||||
|
||||
/*
|
||||
* Convert a vieter_dynarray into an array by freeing all its surrounding
|
||||
* components and returning the underlying array pointer.
|
||||
*/
|
||||
char **vieter_dynarray_convert(vieter_dynarray *da);
|
||||
|
||||
#endif
|
||||
Reference in a new issue