refactor dynamic array: update default size definitions and improve header guard
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
#pragma once
|
||||
#ifndef DYNAMIC_ARRAY_H
|
||||
#define DYNAMIC_ARRAY_H
|
||||
|
||||
#define DYNAMIC_ARRAY_VERSION_MAJOR 0
|
||||
#define DYNAMIC_ARRAY_VERSION_MINOR 1
|
||||
#define DYNAMIC_ARRAY_VERSION_BUILD 0
|
||||
#define DYNAMIC_ARRAY_VERSION ((DYNAMIC_ARRAY_VERSION_MAJOR << 16) | (DYNAMIC_ARRAY_VERSION_MINOR << 8) | DYNAMIC_ARRAY_VERSION_BUILD)
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#define DEFAULT_ARRAY_SIZE 10
|
||||
#define DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE 10
|
||||
|
||||
|
||||
typedef struct {
|
||||
@@ -20,8 +26,8 @@ typedef struct {
|
||||
} ArrayCreateOptions;
|
||||
|
||||
|
||||
#define DEFAULT_ARRAY_CREATE_OPTIONS \
|
||||
(ArrayCreateOptions){ DEFAULT_ARRAY_SIZE, sizeof(int) }
|
||||
#define DYNAMIC_ARRAY_DEFAULT_ARRAY_CREATE_OPTIONS \
|
||||
(ArrayCreateOptions){ DYNAMIC_ARRAY_DEFAULT_ARRAY_SIZE, sizeof(int) }
|
||||
|
||||
Array *array_create(const ArrayCreateOptions *options);
|
||||
|
||||
@@ -53,4 +59,7 @@ size_t array_get_capacity(const Array *p_array);
|
||||
#define array_set_value_as(type, arr, idx, value) \
|
||||
((sizeof(type) == (arr)->element_size) ? \
|
||||
(array_set_value((arr), (idx), (value)), 0) : \
|
||||
-1)
|
||||
-1)
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user