refactor dynamic array: enhance element size handling, update memory management, and improve API functions
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
|
||||
|
||||
typedef struct Array {
|
||||
int *value;
|
||||
void *value;
|
||||
size_t element_size;
|
||||
|
||||
int size;
|
||||
int capacity;
|
||||
} Array;
|
||||
@@ -12,11 +14,12 @@ typedef struct Array {
|
||||
|
||||
typedef struct ArrayCreateOptions {
|
||||
int initial_size;
|
||||
size_t element_size;
|
||||
} ArrayCreateOptions;
|
||||
|
||||
|
||||
#define DEFAULT_ARRAY_CREATE_OPTIONS \
|
||||
(ArrayCreateOptions){ DEFAULT_ARRAY_SIZE }
|
||||
(ArrayCreateOptions){ DEFAULT_ARRAY_SIZE, sizeof(int) }
|
||||
|
||||
Array *array_create(const ArrayCreateOptions *options);
|
||||
|
||||
@@ -27,10 +30,10 @@ void array_deconstructor(Array **pp_array);
|
||||
void array_resize(Array *p_array, int new_size);
|
||||
|
||||
|
||||
int *array_get_value(const Array *p_array, int index);
|
||||
void *array_get_value(const Array *p_array, int index);
|
||||
|
||||
|
||||
void array_set_value(Array *p_array, int index, int value);
|
||||
void array_set_value(Array *p_array, int index, const void *value);
|
||||
|
||||
|
||||
int array_get_size(const Array *p_array);
|
||||
|
||||
Reference in New Issue
Block a user