Maintenance:

Separate big macros into several smaller ones
This commit is contained in:
Patrick Pelissier committed 2023-01-22 23:33:13 +01:00
1 parent 8e4ac99a35
commit 97ff413f01
2 files changed
+37 -17

No files matched your search

+14 -5
View File
@@ -60,9 +60,9 @@
#define M_ARRAY_INIT_VALUE() \ #define M_ARRAY_INIT_VALUE() \
{ { 0, 0, NULL } } { { 0, 0, NULL } }
/********************************************************************************/ /*****************************************************************************/
/********************************** INTERNAL ************************************/ /********************************** INTERNAL *********************************/
/********************************************************************************/ /*****************************************************************************/
/* Deferred evaluation for the oplist definition, /* Deferred evaluation for the oplist definition,
so that all arguments are evaluated before further expansion */ so that all arguments are evaluated before further expansion */
@@ -135,6 +135,7 @@
,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \ ,M_IF_METHOD(DEL, oplist)(DEL(M_GET_DEL oplist),) \
) )
/* Define the internal contract of an array */ /* Define the internal contract of an array */
#define M_ARRA4_CONTRACT(a) do { \ #define M_ARRA4_CONTRACT(a) do { \
M_ASSERT (a != NULL); \ M_ASSERT (a != NULL); \
@@ -143,6 +144,7 @@
M_ASSERT (a->alloc == 0 || a->ptr != NULL); \ M_ASSERT (a->alloc == 0 || a->ptr != NULL); \
} while (0) } while (0)
/* Deferred evaluation for the array definition, /* Deferred evaluation for the array definition,
so that all arguments are fully evaluated before further expansion so that all arguments are fully evaluated before further expansion
(ensuring good performance) (ensuring good performance)
@@ -167,6 +169,12 @@
- it_t: alias for the iterator of the array - it_t: alias for the iterator of the array
*/ */
#define M_ARRA4_DEF_P3(name, type, oplist, array_t, it_t) \ #define M_ARRA4_DEF_P3(name, type, oplist, array_t, it_t) \
M_ARRA4_DEF_TYPE(name, type, oplist, array_t, it_t) \
M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \
M_ARRA4_DEF_CORE(name, type, oplist, array_t, it_t)
/* Define the types */
#define M_ARRA4_DEF_TYPE(name, type, oplist, array_t, it_t) \
\ \
/* Define a dynamic array */ \ /* Define a dynamic array */ \
typedef struct M_C(name, _s) { \ typedef struct M_C(name, _s) { \
@@ -187,8 +195,9 @@
typedef array_t M_C(name, _ct); \ typedef array_t M_C(name, _ct); \
typedef it_t M_C(name, _it_ct); \ typedef it_t M_C(name, _it_ct); \
typedef type M_C(name, _subtype_ct); \ typedef type M_C(name, _subtype_ct); \
\
M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ /* Define the core functions */
#define M_ARRA4_DEF_CORE(name, type, oplist, array_t, it_t) \
\ \
static inline void \ static inline void \
M_C(name, _init)(array_t v) \ M_C(name, _init)(array_t v) \
+23 -12
View File
@@ -56,7 +56,10 @@
#define M_USE_DEQUE_DEFAULT_SIZE 8 #define M_USE_DEQUE_DEFAULT_SIZE 8
#endif #endif
/********************************** INTERNAL ************************************/
/*****************************************************************************/
/********************************* INTERNAL **********************************/
/*****************************************************************************/
/* Define the internal contract of a deque */ /* Define the internal contract of a deque */
#define M_D3QU3_CONTRACT(d) do { \ #define M_D3QU3_CONTRACT(d) do { \
@@ -93,16 +96,22 @@
- node_t: alias for node_t [ node ] - node_t: alias for node_t [ node ]
*/ */
#define M_D3QU3_DEF_P3(name, type, oplist, deque_t, it_t, node_t) \ #define M_D3QU3_DEF_P3(name, type, oplist, deque_t, it_t, node_t) \
M_D3QU3_DEF_TYPE(name, type, oplist, deque_t, it_t, node_t) \
M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \
M_D3QU3_DEF_CORE(name, type, oplist, deque_t, it_t, node_t)
/* Define the types.
It is a linked list of buckets of the types,
each new created bucket size grows compared to the previous one
resulting in:
strict O(1) for push/pop
O(ln(n)) for random access.
No insert / delete operations are planned.
[Could be done in O(n) complexity if needed]
Define the bucket (aka node) structure.
*/
#define M_D3QU3_DEF_TYPE(name, type, oplist, deque_t, it_t, node_t) \
\ \
/* It is a linked list of buckets of the types, \
each new created bucket size grows compared to the previous one \
resulting in: \
strict O(1) for push/pop \
O(ln(n)) for random access. \
No insert / delete operations are planned. \
[Could be done in O(n) complexity if needed] \
Define the bucket (aka node) structure. \
*/ \
typedef struct M_C(name, _node_s) { \ typedef struct M_C(name, _node_s) { \
ILIST_INTERFACE(M_C(name, _node_list), struct M_C(name, _node_s)); \ ILIST_INTERFACE(M_C(name, _node_list), struct M_C(name, _node_s)); \
size_t size; \ size_t size; \
@@ -115,6 +124,7 @@
so we register as a DEL operator the FREE operator of the oplist. \ so we register as a DEL operator the FREE operator of the oplist. \
The interfaces are compatible. \ The interfaces are compatible. \
*/ \ */ \
/* FIXME: How can I separate public types and private implementation? */ \
ILIST_DEF(M_C(name, _node_list), node_t, (DEL(M_GET_FREE oplist)) ) \ ILIST_DEF(M_C(name, _node_list), node_t, (DEL(M_GET_FREE oplist)) ) \
\ \
/* Define an internal iterator */ \ /* Define an internal iterator */ \
@@ -153,8 +163,9 @@
typedef deque_t M_C(name, _ct); \ typedef deque_t M_C(name, _ct); \
typedef type M_C(name, _subtype_ct); \ typedef type M_C(name, _subtype_ct); \
typedef it_t M_C(name, _it_ct); \ typedef it_t M_C(name, _it_ct); \
\
M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \ /* Define the core functions */
#define M_D3QU3_DEF_CORE(name, type, oplist, deque_t, it_t, node_t) \
\ \
/* Allocate a new node for a deque */ \ /* Allocate a new node for a deque */ \
static inline node_t* \ static inline node_t* \