Rename macros:
* CAT* --> M_C*
This commit is contained in:
1 parent
8613bdbca6
commit
cb433aa2a8
15 files changed
+806
-809
No files matched your search
@@ -45,7 +45,7 @@
|
||||
|
||||
#define ALGOI_DEF(name, container_t, cont_oplist, type_t, type_oplist, it_t) \
|
||||
\
|
||||
static inline void CAT(name, _find) (it_t it, container_t l, const type_t data) \
|
||||
static inline void M_C(name, _find) (it_t it, container_t l, const type_t data) \
|
||||
{ \
|
||||
for (M_GET_IT_FIRST cont_oplist (it, l); \
|
||||
!M_GET_IT_END_P cont_oplist (it) ; \
|
||||
@@ -55,14 +55,14 @@
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static inline bool CAT(name, _contains) (container_t l, const type_t data) \
|
||||
static inline bool M_C(name, _contains) (container_t l, const type_t data) \
|
||||
{ \
|
||||
it_t it; \
|
||||
CAT(name,_find)(it, l, data); \
|
||||
M_C(name,_find)(it, l, data); \
|
||||
return !M_GET_IT_END_P cont_oplist (it); \
|
||||
} \
|
||||
\
|
||||
static inline size_t CAT(name, _count) (container_t l, const type_t data) \
|
||||
static inline size_t M_C(name, _count) (container_t l, const type_t data) \
|
||||
{ \
|
||||
it_t it; \
|
||||
size_t count = 0; \
|
||||
@@ -75,7 +75,7 @@
|
||||
return count; \
|
||||
} \
|
||||
\
|
||||
static inline void CAT(name, _map) (container_t l, \
|
||||
static inline void M_C(name, _map) (container_t l, \
|
||||
void (*f)(type_t const) ) \
|
||||
{ \
|
||||
for M_EACH(item, l, cont_oplist) { \
|
||||
@@ -84,7 +84,7 @@
|
||||
} \
|
||||
\
|
||||
M_IF_METHOD(CMP, type_oplist)( \
|
||||
static inline type_t *CAT(name, _min) (/*const*/ container_t l) \
|
||||
static inline type_t *M_C(name, _min) (/*const*/ container_t l) \
|
||||
{ \
|
||||
type_t *min = NULL; \
|
||||
for M_EACH(cref, l, cont_oplist) { \
|
||||
@@ -95,7 +95,7 @@
|
||||
return min; \
|
||||
} \
|
||||
\
|
||||
static inline type_t *CAT(name, _max) (/*const*/ container_t l) \
|
||||
static inline type_t *M_C(name, _max) (/*const*/ container_t l) \
|
||||
{ \
|
||||
type_t *max = NULL; \
|
||||
for M_EACH(cref, l, cont_oplist) { \
|
||||
@@ -106,7 +106,7 @@
|
||||
return max; \
|
||||
} \
|
||||
\
|
||||
static inline void CAT(name, _minmax) (type_t **min_p, type_t **max_p, \
|
||||
static inline void M_C(name, _minmax) (type_t **min_p, type_t **max_p, \
|
||||
/*const*/ container_t l) \
|
||||
{ \
|
||||
type_t *min = NULL; \
|
||||
@@ -129,17 +129,17 @@
|
||||
/* - a selection sort */ \
|
||||
M_IF_METHOD(SORT, cont_oplist)( \
|
||||
/* optimized sort for container */ \
|
||||
static inline int CAT(name,_sort_cmp)(const type_t*a,const type_t*b) {\
|
||||
static inline int M_C(name,_sort_cmp)(const type_t*a,const type_t*b) {\
|
||||
return M_GET_CMP type_oplist(*a, *b); \
|
||||
} \
|
||||
static inline void CAT(name, _sort)(container_t l) \
|
||||
static inline void M_C(name, _sort)(container_t l) \
|
||||
{ \
|
||||
M_GET_SORT cont_oplist(l, CAT(name, _sort_cmp)); \
|
||||
M_GET_SORT cont_oplist(l, M_C(name, _sort_cmp)); \
|
||||
} \
|
||||
, \
|
||||
M_IF_METHOD(IT_PREVIOUS, cont_oplist)( \
|
||||
/* generic insertion sort */ \
|
||||
static inline void CAT(name, _sort)(container_t l) \
|
||||
static inline void M_C(name, _sort)(container_t l) \
|
||||
{ \
|
||||
it_t it1; \
|
||||
it_t it2; \
|
||||
@@ -165,7 +165,7 @@
|
||||
} \
|
||||
, \
|
||||
/* generic selection sort */ \
|
||||
static inline void CAT(name, _sort)(container_t l) \
|
||||
static inline void M_C(name, _sort)(container_t l) \
|
||||
{ \
|
||||
it_t it1; \
|
||||
it_t it2; \
|
||||
|
||||
@@ -50,33 +50,33 @@
|
||||
/********************************** INTERNAL ************************************/
|
||||
|
||||
#define ARRAYI_OPLIST(name, oplist) \
|
||||
(INIT(CAT3(array_, name, _init)) \
|
||||
,INIT_SET(CAT3(array_, name, _init_set)) \
|
||||
,SET(CAT3(array_, name, _set)) \
|
||||
,CLEAR(CAT3(array_, name, _clear)) \
|
||||
,INIT_MOVE(CAT3(array_, name, _init_move)) \
|
||||
,MOVE(CAT3(array_, name, _move)) \
|
||||
,TYPE(CAT3(array_,name,_t)) \
|
||||
,SUBTYPE(CAT3(array_type_,name,_t)) \
|
||||
,IT_TYPE(CAT3(array_it_,name,_t)) \
|
||||
,IT_FIRST(CAT3(array_,name,_it)) \
|
||||
,IT_SET(CAT3(array_,name,_it_set)) \
|
||||
,IT_END_P(CAT3(array_,name,_end_p)) \
|
||||
,IT_LAST_P(CAT3(array_,name,_last_p)) \
|
||||
,IT_EQUAL_P(CAT3(array_,name,_it_equal_p)) \
|
||||
,IT_NEXT(CAT3(array_,name,_next)) \
|
||||
,IT_PREVIOUS(CAT3(array_,name,_previous)) \
|
||||
,IT_REF(CAT3(array_,name,_ref)) \
|
||||
,IT_CREF(CAT3(array_,name,_cref)) \
|
||||
,CLEAN(CAT3(array_,name,_clean)) \
|
||||
,PUSH(CAT3(array_,name,_push_back)) \
|
||||
,POP(CAT3(array_,name,_pop_back)) \
|
||||
(INIT(M_C3(array_, name, _init)) \
|
||||
,INIT_SET(M_C3(array_, name, _init_set)) \
|
||||
,SET(M_C3(array_, name, _set)) \
|
||||
,CLEAR(M_C3(array_, name, _clear)) \
|
||||
,INIT_MOVE(M_C3(array_, name, _init_move)) \
|
||||
,MOVE(M_C3(array_, name, _move)) \
|
||||
,TYPE(M_C3(array_,name,_t)) \
|
||||
,SUBTYPE(M_C3(array_type_,name,_t)) \
|
||||
,IT_TYPE(M_C3(array_it_,name,_t)) \
|
||||
,IT_FIRST(M_C3(array_,name,_it)) \
|
||||
,IT_SET(M_C3(array_,name,_it_set)) \
|
||||
,IT_END_P(M_C3(array_,name,_end_p)) \
|
||||
,IT_LAST_P(M_C3(array_,name,_last_p)) \
|
||||
,IT_EQUAL_P(M_C3(array_,name,_it_equal_p)) \
|
||||
,IT_NEXT(M_C3(array_,name,_next)) \
|
||||
,IT_PREVIOUS(M_C3(array_,name,_previous)) \
|
||||
,IT_REF(M_C3(array_,name,_ref)) \
|
||||
,IT_CREF(M_C3(array_,name,_cref)) \
|
||||
,CLEAN(M_C3(array_,name,_clean)) \
|
||||
,PUSH(M_C3(array_,name,_push_back)) \
|
||||
,POP(M_C3(array_,name,_pop_back)) \
|
||||
,OPLIST(oplist) \
|
||||
,M_IF_METHOD(CMP, oplist)(SORT(CAT3(array_, name, _sort)),) \
|
||||
,M_IF_METHOD(GET_STR, oplist)(GET_STR(CAT3(array_, name, _get_str)),) \
|
||||
,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(CAT3(array_, name, _out_str)),) \
|
||||
,M_IF_METHOD(IN_STR, oplist)(IN_STR(CAT3(array_, name, _in_str)),) \
|
||||
,M_IF_METHOD(EQUAL, oplist)(EQUAL(CAT3(array_, type, _equal_p)),) \
|
||||
,M_IF_METHOD(CMP, oplist)(SORT(M_C3(array_, name, _sort)),) \
|
||||
,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C3(array_, name, _get_str)),) \
|
||||
,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C3(array_, name, _out_str)),) \
|
||||
,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C3(array_, name, _in_str)),) \
|
||||
,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C3(array_, type, _equal_p)),) \
|
||||
)
|
||||
|
||||
// Compute alloc from size.
|
||||
@@ -84,33 +84,33 @@
|
||||
|
||||
// Internal
|
||||
#define ARRAYI_DEF2(name, type, oplist) \
|
||||
typedef struct CAT3(array_, name, _s) { \
|
||||
typedef struct M_C3(array_, name, _s) { \
|
||||
size_t size, alloc; \
|
||||
type *ptr; \
|
||||
} CAT3(array_, name,_t)[1]; \
|
||||
} M_C3(array_, name,_t)[1]; \
|
||||
\
|
||||
typedef union { \
|
||||
type *ptr; \
|
||||
const type *cptr; \
|
||||
} CAT3(array_union_, name,_t); \
|
||||
} M_C3(array_union_, name,_t); \
|
||||
\
|
||||
typedef type CAT3(array_type_,name,_t); \
|
||||
typedef type M_C3(array_type_,name,_t); \
|
||||
\
|
||||
typedef struct CAT3(array_it_,name,_s) { \
|
||||
typedef struct M_C3(array_it_,name,_s) { \
|
||||
size_t index; \
|
||||
struct CAT3(array_, name, _s) *array; \
|
||||
} CAT3(array_it_,name,_t)[1]; \
|
||||
struct M_C3(array_, name, _s) *array; \
|
||||
} M_C3(array_it_,name,_t)[1]; \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(array_, name, _const_cast)(type *ptr) \
|
||||
M_C3(array_, name, _const_cast)(type *ptr) \
|
||||
{ \
|
||||
CAT3(array_union_, name,_t) u; \
|
||||
M_C3(array_union_, name,_t) u; \
|
||||
u.ptr = ptr; \
|
||||
return u.cptr; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _init)(CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _init)(M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
v->size = v->alloc = 0; \
|
||||
@@ -118,7 +118,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _clean)(CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _clean)(M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL && v->size <= v->alloc); \
|
||||
for(size_t i = 0; i < v->size; i++) \
|
||||
@@ -127,18 +127,18 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _clear)(CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _clear)(M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL && v->size <= v->alloc); \
|
||||
CAT3(array_, name, _clean)(v); \
|
||||
M_C3(array_, name, _clean)(v); \
|
||||
M_MEMORY_FREE(v->ptr); \
|
||||
v->alloc = 0; \
|
||||
v->ptr = NULL; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _set)(CAT3(array_, name,_t) d, \
|
||||
const CAT3(array_, name,_t) s) \
|
||||
M_C3(array_, name, _set)(M_C3(array_, name,_t) d, \
|
||||
const M_C3(array_, name,_t) s) \
|
||||
{ \
|
||||
assert (d != NULL && s != NULL \
|
||||
&& d->size <= d->alloc && s->size <= s->alloc); \
|
||||
@@ -165,17 +165,17 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _init_set)(CAT3(array_, name,_t) d, \
|
||||
const CAT3(array_, name,_t) s) \
|
||||
M_C3(array_, name, _init_set)(M_C3(array_, name,_t) d, \
|
||||
const M_C3(array_, name,_t) s) \
|
||||
{ \
|
||||
assert (d != s); \
|
||||
CAT3(array_, name, _init)(d); \
|
||||
CAT3(array_, name, _set)(d, s); \
|
||||
M_C3(array_, name, _init)(d); \
|
||||
M_C3(array_, name, _set)(d, s); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _init_move)(CAT3(array_, name,_t) d, \
|
||||
CAT3(array_, name,_t) s) \
|
||||
M_C3(array_, name, _init_move)(M_C3(array_, name,_t) d, \
|
||||
M_C3(array_, name,_t) s) \
|
||||
{ \
|
||||
assert (d != s); \
|
||||
d->size = s->size; \
|
||||
@@ -186,30 +186,30 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _move)(CAT3(array_, name,_t) d, \
|
||||
CAT3(array_, name,_t) s) \
|
||||
M_C3(array_, name, _move)(M_C3(array_, name,_t) d, \
|
||||
M_C3(array_, name,_t) s) \
|
||||
{ \
|
||||
assert (d != s); \
|
||||
CAT3(array_, name, _clear)(d); \
|
||||
CAT3(array_, name, _init_move)(d, s); \
|
||||
M_C3(array_, name, _clear)(d); \
|
||||
M_C3(array_, name, _init_move)(d, s); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _set_at)(CAT3(array_, name,_t) v, size_t i, type x) \
|
||||
M_C3(array_, name, _set_at)(M_C3(array_, name,_t) v, size_t i, type x) \
|
||||
{ \
|
||||
assert(v != NULL && i < v->size && v->ptr != NULL); \
|
||||
M_GET_SET oplist(v->ptr[i], x); \
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(array_, name, _back)(CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _back)(M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL && v->ptr != NULL); \
|
||||
return CAT3(array_, name, _const_cast)(&v->ptr[v->size-1]); \
|
||||
return M_C3(array_, name, _const_cast)(&v->ptr[v->size-1]); \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(array_, name, _push_raw)(CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _push_raw)(M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL && v->size <= v->alloc); \
|
||||
if (v->size >= v->alloc) { \
|
||||
@@ -231,20 +231,20 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _push_back)(CAT3(array_, name,_t) v, type const x) \
|
||||
M_C3(array_, name, _push_back)(M_C3(array_, name,_t) v, type const x) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
type *data = CAT3(array_, name, _push_raw)(v); \
|
||||
type *data = M_C3(array_, name, _push_raw)(v); \
|
||||
if (data == NULL) \
|
||||
return; \
|
||||
M_GET_INIT_SET oplist(*data, x); \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(array_, name, _push_new)(CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _push_new)(M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
type *data = CAT3(array_, name, _push_raw)(v); \
|
||||
type *data = M_C3(array_, name, _push_raw)(v); \
|
||||
if (data == NULL) \
|
||||
return NULL; \
|
||||
M_GET_INIT oplist(*data); \
|
||||
@@ -252,7 +252,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _push_at)(CAT3(array_, name,_t) v, size_t key, type const x) \
|
||||
M_C3(array_, name, _push_at)(M_C3(array_, name,_t) v, size_t key, type const x) \
|
||||
{ \
|
||||
assert (v != NULL && key <= v->size && v->size <= v->alloc); \
|
||||
if (v->size >= v->alloc) { \
|
||||
@@ -274,7 +274,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _resize)(CAT3(array_, name, _t) v, size_t size) \
|
||||
M_C3(array_, name, _resize)(M_C3(array_, name, _t) v, size_t size) \
|
||||
{ \
|
||||
assert (v != NULL && v->size <= v->alloc); \
|
||||
if (v->size > size) { \
|
||||
@@ -302,7 +302,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _set_at2)(CAT3(array_, name,_t) v, size_t idx, type x) \
|
||||
M_C3(array_, name, _set_at2)(M_C3(array_, name,_t) v, size_t idx, type x) \
|
||||
{ \
|
||||
assert (v != NULL && v->size <= v->alloc); \
|
||||
size_t size = idx + 1; \
|
||||
@@ -327,7 +327,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _pop_back)(type *dest, CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _pop_back)(type *dest, M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL && v->size > 0 && v->ptr != NULL); \
|
||||
v->size--; \
|
||||
@@ -341,28 +341,28 @@
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(array_, name, _empty_p)(const CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _empty_p)(const M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
return v->size == 0; \
|
||||
} \
|
||||
\
|
||||
static inline size_t \
|
||||
CAT3(array_, name, _size)(const CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _size)(const M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
return v->size; \
|
||||
} \
|
||||
\
|
||||
static inline size_t \
|
||||
CAT3(array_, name, _capacity)(const CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _capacity)(const M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
return v->alloc; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _pop_at)(type *dest, CAT3(array_, name,_t) v, size_t i) \
|
||||
M_C3(array_, name, _pop_at)(type *dest, M_C3(array_, name,_t) v, size_t i) \
|
||||
{ \
|
||||
assert(v != NULL && v->size > 0 && i < v->size && v->ptr != NULL); \
|
||||
if (dest) \
|
||||
@@ -377,7 +377,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _insert_v)(CAT3(array_, name,_t) v, size_t i, size_t j) \
|
||||
M_C3(array_, name, _insert_v)(M_C3(array_, name,_t) v, size_t i, size_t j) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
assert(i < v->size && j <= v->size && i < j); \
|
||||
@@ -399,7 +399,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _remove_v)(CAT3(array_, name,_t) v, size_t i, size_t j) \
|
||||
M_C3(array_, name, _remove_v)(M_C3(array_, name,_t) v, size_t i, size_t j) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
assert(i < v->size && j <= v->size && i < j && v->ptr != NULL); \
|
||||
@@ -410,13 +410,13 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_,name, _remove)(CAT3(array_, name,_t) v, size_t i) \
|
||||
M_C3(array_,name, _remove)(M_C3(array_, name,_t) v, size_t i) \
|
||||
{ \
|
||||
CAT3(array_, name, _pop_at)(NULL, v, i); \
|
||||
M_C3(array_, name, _pop_at)(NULL, v, i); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _swap)(CAT3(array_, name,_t) v, size_t i, size_t j) \
|
||||
M_C3(array_, name, _swap)(M_C3(array_, name,_t) v, size_t i, size_t j) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
assert(i < v->size && j < v->size && v->ptr != NULL); \
|
||||
@@ -434,7 +434,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _shrink_to_fit)(CAT3(array_, name,_t) v) \
|
||||
M_C3(array_, name, _shrink_to_fit)(M_C3(array_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL && v->size <= v->alloc); \
|
||||
v->ptr = M_MEMORY_REALLOC (type, v->ptr, v->size); \
|
||||
@@ -443,22 +443,22 @@
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(array_, name, _get)(CAT3(array_, name,_t) v, size_t i) \
|
||||
M_C3(array_, name, _get)(M_C3(array_, name,_t) v, size_t i) \
|
||||
{ \
|
||||
assert (v != NULL && i < v->size && v->ptr != NULL); \
|
||||
return &v->ptr[i]; \
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(array_, name, _cget)(const CAT3(array_, name,_t) v, size_t i) \
|
||||
M_C3(array_, name, _cget)(const M_C3(array_, name,_t) v, size_t i) \
|
||||
{ \
|
||||
assert(v != NULL && i < v->size && v->ptr != NULL); \
|
||||
return CAT3(array_, name, _const_cast)(&v->ptr[i]); \
|
||||
return M_C3(array_, name, _const_cast)(&v->ptr[i]); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _it)(CAT3(array_it_,name,_t) it, \
|
||||
CAT3(array_, name, _t) v) \
|
||||
M_C3(array_, name, _it)(M_C3(array_it_,name,_t) it, \
|
||||
M_C3(array_, name, _t) v) \
|
||||
{ \
|
||||
assert (it != NULL && v != NULL); \
|
||||
it->index = 0; \
|
||||
@@ -466,8 +466,8 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _it_set)(CAT3(array_it_,name,_t) it, \
|
||||
const CAT3(array_it_, name, _t) org) \
|
||||
M_C3(array_, name, _it_set)(M_C3(array_it_,name,_t) it, \
|
||||
const M_C3(array_it_, name, _t) org) \
|
||||
{ \
|
||||
assert (it != NULL && org != NULL); \
|
||||
it->index = org->index; \
|
||||
@@ -475,14 +475,14 @@
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(array_, name, _end_p)(const CAT3(array_it_, name, _t) it) \
|
||||
M_C3(array_, name, _end_p)(const M_C3(array_it_, name, _t) it) \
|
||||
{ \
|
||||
assert(it != NULL && it->array != NULL); \
|
||||
return (it->index) >= it->array->size; \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(array_, name, _last_p)(const CAT3(array_it_, name, _t) it) \
|
||||
M_C3(array_, name, _last_p)(const M_C3(array_it_, name, _t) it) \
|
||||
{ \
|
||||
assert(it != NULL && it->array != NULL); \
|
||||
/* Case i=0 & s=0 ==> true since unsigned type */ \
|
||||
@@ -490,22 +490,22 @@
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(array_, name, _it_equal_p)(const CAT3(array_it_, name,_t) it1, \
|
||||
const CAT3(array_it_, name,_t) it2) \
|
||||
M_C3(array_, name, _it_equal_p)(const M_C3(array_it_, name,_t) it1, \
|
||||
const M_C3(array_it_, name,_t) it2) \
|
||||
{ \
|
||||
assert(it1 != NULL && it2 != NULL); \
|
||||
return it1->array == it2->array && it1->index == it2->index; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _next)(CAT3(array_it_,name,_t) it) \
|
||||
M_C3(array_, name, _next)(M_C3(array_it_,name,_t) it) \
|
||||
{ \
|
||||
assert(it != NULL && it->array != NULL); \
|
||||
it->index ++; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _previous)(CAT3(array_it_,name,_t) it) \
|
||||
M_C3(array_, name, _previous)(M_C3(array_it_,name,_t) it) \
|
||||
{ \
|
||||
assert(it != NULL && it->array != NULL); \
|
||||
/* In the case index=0, it will be set to (unsigned) -1 \
|
||||
@@ -514,29 +514,29 @@
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(array_, name, _ref)(CAT3(array_it_, name,_t) it) \
|
||||
M_C3(array_, name, _ref)(M_C3(array_it_, name,_t) it) \
|
||||
{ \
|
||||
assert(it != NULL); \
|
||||
return CAT3(array_, name, _get)(it->array, it->index); \
|
||||
return M_C3(array_, name, _get)(it->array, it->index); \
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(array_, name, _cref)(const CAT3(array_it_, name,_t) it) \
|
||||
M_C3(array_, name, _cref)(const M_C3(array_it_, name,_t) it) \
|
||||
{ \
|
||||
assert(it != NULL); \
|
||||
return CAT3(array_, name, _cget)(it->array, it->index); \
|
||||
return M_C3(array_, name, _cget)(it->array, it->index); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(array_, name, _insert)(CAT3(array_it_, name,_t) it, type const x) \
|
||||
M_C3(array_, name, _insert)(M_C3(array_it_, name,_t) it, type const x) \
|
||||
{ \
|
||||
assert(it != NULL); \
|
||||
CAT3(array_, name, _push_at)(it->array, it->index, x); \
|
||||
M_C3(array_, name, _push_at)(it->array, it->index, x); \
|
||||
} \
|
||||
\
|
||||
M_IF_METHOD(CMP, oplist) \
|
||||
( \
|
||||
static inline void CAT3(array_, name, _sort)(CAT3(array_, name,_t) l, \
|
||||
static inline void M_C3(array_, name, _sort)(M_C3(array_, name,_t) l, \
|
||||
int (*func_type) (const type *a, const type *b))\
|
||||
{ \
|
||||
/* Using qsort is more compact but slower than a full templated \
|
||||
@@ -550,18 +550,18 @@
|
||||
\
|
||||
M_IF_METHOD(GET_STR, oplist)( \
|
||||
static inline void \
|
||||
CAT3(array_, name, _get_str)(string_t str, CAT3(array_, name,_t) array, \
|
||||
M_C3(array_, name, _get_str)(string_t str, M_C3(array_, name,_t) array, \
|
||||
bool append) \
|
||||
{ \
|
||||
assert (str != NULL && array != NULL); \
|
||||
(append ? string_cat_str : string_set_str) (str, "["); \
|
||||
CAT3(array_it_, name, _t) it; \
|
||||
for (CAT3(array_, name, _it)(it, array) ; \
|
||||
!CAT3(array_, name, _end_p)(it); \
|
||||
CAT3(array_, name, _next)(it)){ \
|
||||
const type *item = CAT3(array_, name, _cref)(it); \
|
||||
M_C3(array_it_, name, _t) it; \
|
||||
for (M_C3(array_, name, _it)(it, array) ; \
|
||||
!M_C3(array_, name, _end_p)(it); \
|
||||
M_C3(array_, name, _next)(it)){ \
|
||||
const type *item = M_C3(array_, name, _cref)(it); \
|
||||
M_GET_GET_STR oplist (str, *item, true); \
|
||||
if (!CAT3(array_, name, _last_p)(it)) \
|
||||
if (!M_C3(array_, name, _last_p)(it)) \
|
||||
string_push_back (str, M_GET_SEPARATOR oplist); \
|
||||
} \
|
||||
string_push_back (str, ']'); \
|
||||
@@ -570,17 +570,17 @@
|
||||
\
|
||||
M_IF_METHOD(OUT_STR, oplist)( \
|
||||
static inline void \
|
||||
CAT3(array_, name, _out_str)(FILE *file, CAT3(array_, name,_t) array) \
|
||||
M_C3(array_, name, _out_str)(FILE *file, M_C3(array_, name,_t) array) \
|
||||
{ \
|
||||
assert (file != NULL && array != NULL); \
|
||||
fprintf (file, "["); \
|
||||
CAT3(array_it_, name, _t) it; \
|
||||
for (CAT3(array_, name, _it)(it, array) ; \
|
||||
!CAT3(array_, name, _end_p)(it); \
|
||||
CAT3(array_, name, _next)(it)){ \
|
||||
const type *item = CAT3(array_, name, _cref)(it); \
|
||||
M_C3(array_it_, name, _t) it; \
|
||||
for (M_C3(array_, name, _it)(it, array) ; \
|
||||
!M_C3(array_, name, _end_p)(it); \
|
||||
M_C3(array_, name, _next)(it)){ \
|
||||
const type *item = M_C3(array_, name, _cref)(it); \
|
||||
M_GET_OUT_STR oplist (file, *item); \
|
||||
if (!CAT3(array_, name, _last_p)(it)) \
|
||||
if (!M_C3(array_, name, _last_p)(it)) \
|
||||
fputc (M_GET_SEPARATOR oplist, file); \
|
||||
} \
|
||||
fprintf (file, "]"); \
|
||||
@@ -589,10 +589,10 @@
|
||||
\
|
||||
M_IF_METHOD(IN_STR, oplist)( \
|
||||
static inline bool \
|
||||
CAT3(array_, name, _in_str)(CAT3(array_, name,_t) array, FILE *file) \
|
||||
M_C3(array_, name, _in_str)(M_C3(array_, name,_t) array, FILE *file) \
|
||||
{ \
|
||||
assert (file != NULL && array != NULL); \
|
||||
CAT3(array_, name,_clean)(array); \
|
||||
M_C3(array_, name,_clean)(array); \
|
||||
char c = fgetc(file); \
|
||||
if (c != '[') return false; \
|
||||
type item; \
|
||||
@@ -600,7 +600,7 @@
|
||||
do { \
|
||||
bool b = M_GET_IN_STR oplist (item, file); \
|
||||
if (!b) { M_GET_CLEAR oplist (item); return false; } \
|
||||
CAT3(array_, name, _push_back)(array, item); \
|
||||
M_C3(array_, name, _push_back)(array, item); \
|
||||
c = fgetc(file); \
|
||||
} while (c == M_GET_SEPARATOR oplist && !feof(file) && !ferror(file)); \
|
||||
M_GET_CLEAR oplist (item); \
|
||||
@@ -610,26 +610,26 @@
|
||||
\
|
||||
M_IF_METHOD(EQUAL, oplist)( \
|
||||
static inline bool \
|
||||
CAT3(array_, name, _equal_p)(CAT3(array_, name,_t) array1, \
|
||||
CAT3(array_, name,_t) array2) \
|
||||
M_C3(array_, name, _equal_p)(M_C3(array_, name,_t) array1, \
|
||||
M_C3(array_, name,_t) array2) \
|
||||
{ \
|
||||
assert (array1 != NULL && array2 != NULL); \
|
||||
if (array1->size != array2->size) return false; \
|
||||
CAT3(array_it_, name, _t) it1; \
|
||||
CAT3(array_it_, name, _t) it2; \
|
||||
CAT3(array_, name, _it)(it1, array1); \
|
||||
CAT3(array_, name, _it)(it2, array2); \
|
||||
while (!CAT3(array_, name, _end_p)(it1) \
|
||||
&&!CAT3(array_, name, _end_p)(it2)) { \
|
||||
const type *item1 = CAT3(array_, name, _cref)(it1); \
|
||||
const type *item2 = CAT3(array_, name, _cref)(it2); \
|
||||
M_C3(array_it_, name, _t) it1; \
|
||||
M_C3(array_it_, name, _t) it2; \
|
||||
M_C3(array_, name, _it)(it1, array1); \
|
||||
M_C3(array_, name, _it)(it2, array2); \
|
||||
while (!M_C3(array_, name, _end_p)(it1) \
|
||||
&&!M_C3(array_, name, _end_p)(it2)) { \
|
||||
const type *item1 = M_C3(array_, name, _cref)(it1); \
|
||||
const type *item2 = M_C3(array_, name, _cref)(it2); \
|
||||
bool b = M_GET_EQUAL oplist (*item1, *item2); \
|
||||
if (!b) return false; \
|
||||
CAT3(array_, name, _next)(it1); \
|
||||
CAT3(array_, name, _next)(it2); \
|
||||
M_C3(array_, name, _next)(it1); \
|
||||
M_C3(array_, name, _next)(it2); \
|
||||
} \
|
||||
return CAT3(array_, name, _end_p)(it1) \
|
||||
&& CAT3(array_, name, _end_p)(it2); \
|
||||
return M_C3(array_, name, _end_p)(it1) \
|
||||
&& M_C3(array_, name, _end_p)(it2); \
|
||||
} \
|
||||
, /* no equal */ ) \
|
||||
\
|
||||
|
||||
+16
-16
@@ -52,17 +52,17 @@ typedef enum {
|
||||
#define BUFFERI_SIZE(m_size) BUFFERI_IF_CTE_SIZE(m_size) (m_size, v->size)
|
||||
|
||||
#define BUFFERI_DEF2(name, type, m_size, policy, oplist) \
|
||||
typedef struct CAT3(buffer_, name, _s) { \
|
||||
typedef struct M_C3(buffer_, name, _s) { \
|
||||
M_MUTEX_T mutex; \
|
||||
M_COND_T there_is_data; \
|
||||
M_COND_T there_is_room_for_data; \
|
||||
BUFFERI_IF_CTE_SIZE(m_size)( ,size_t size;) \
|
||||
size_t idx_prod, idx_cons, number; \
|
||||
type *data; \
|
||||
} CAT3(buffer_, name,_t)[1]; \
|
||||
} M_C3(buffer_, name,_t)[1]; \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(buffer_, name, _init)(CAT3(buffer_, name,_t) v, size_t size) \
|
||||
M_C3(buffer_, name, _init)(M_C3(buffer_, name,_t) v, size_t size) \
|
||||
{ \
|
||||
assert( size > 0); \
|
||||
BUFFERI_IF_CTE_SIZE(m_size)(assert(size == m_size), v->size = size); \
|
||||
@@ -85,7 +85,7 @@ static inline void \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(bufferi_, name, _clear_obj)(CAT3(buffer_, name,_t) v) \
|
||||
M_C3(bufferi_, name, _clear_obj)(M_C3(buffer_, name,_t) v) \
|
||||
{ \
|
||||
if (((policy)&BUFFER_PUSH_INIT_POP_MOVE) == 0) { \
|
||||
for(size_t i = 0; i < BUFFERI_SIZE(m_size); i++) \
|
||||
@@ -103,10 +103,10 @@ static inline void \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(buffer_, name, _clear)(CAT3(buffer_, name,_t) v) \
|
||||
M_C3(buffer_, name, _clear)(M_C3(buffer_, name,_t) v) \
|
||||
{ \
|
||||
int rc; \
|
||||
CAT3(bufferi_, name, _clear_obj)(v); \
|
||||
M_C3(bufferi_, name, _clear_obj)(v); \
|
||||
M_MEMORY_FREE (v->data); \
|
||||
v->data = NULL; \
|
||||
if (((policy) & BUFFER_THREAD_UNSAFE) != BUFFER_THREAD_UNSAFE) { \
|
||||
@@ -120,13 +120,13 @@ static inline void \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(buffer_, name, _clean)(CAT3(buffer_, name,_t) v) \
|
||||
M_C3(buffer_, name, _clean)(M_C3(buffer_, name,_t) v) \
|
||||
{ \
|
||||
assert (v->number <= BUFFERI_SIZE(m_size)); \
|
||||
if (((policy) & BUFFER_THREAD_UNSAFE) != BUFFER_THREAD_UNSAFE) \
|
||||
M_MUTEX_LOCK(v->mutex); \
|
||||
if (((policy)&BUFFER_PUSH_INIT_POP_MOVE) != 0) \
|
||||
CAT3(bufferi_, name, _clear_obj)(v); \
|
||||
M_C3(bufferi_, name, _clear_obj)(v); \
|
||||
if (((policy) & BUFFER_THREAD_UNSAFE) != BUFFER_THREAD_UNSAFE) { \
|
||||
M_COND_SIGNAL(v->there_is_room_for_data); \
|
||||
M_MUTEX_UNLOCK(v->mutex); \
|
||||
@@ -134,26 +134,26 @@ static inline void \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(buffer_, name, _empty_p)(CAT3(buffer_, name,_t) v) \
|
||||
M_C3(buffer_, name, _empty_p)(M_C3(buffer_, name,_t) v) \
|
||||
{ \
|
||||
assert(v->number <= BUFFERI_SIZE(m_size)); \
|
||||
return v->number == 0; \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(buffer_, name, _full_p)(CAT3(buffer_, name,_t) v) \
|
||||
M_C3(buffer_, name, _full_p)(M_C3(buffer_, name,_t) v) \
|
||||
{ \
|
||||
assert(v->number <= BUFFERI_SIZE(m_size)); \
|
||||
return v->number == BUFFERI_SIZE(m_size); \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(buffer_, name, _push)(CAT3(buffer_, name,_t) v, type const data) \
|
||||
M_C3(buffer_, name, _push)(M_C3(buffer_, name,_t) v, type const data) \
|
||||
{ \
|
||||
if (((policy) & BUFFER_THREAD_UNSAFE) != BUFFER_THREAD_UNSAFE) { \
|
||||
M_MUTEX_LOCK(v->mutex); \
|
||||
while (((policy)&BUFFER_PUSH_OVERWRITE) == 0 \
|
||||
&& CAT3(buffer_, name, _full_p)(v)) { \
|
||||
&& M_C3(buffer_, name, _full_p)(v)) { \
|
||||
if (((policy) & BUFFER_UNBLOCKING) == BUFFER_UNBLOCKING) { \
|
||||
M_MUTEX_UNLOCK(v->mutex); \
|
||||
return false; \
|
||||
@@ -161,7 +161,7 @@ static inline void \
|
||||
M_COND_WAIT(v->there_is_room_for_data, v->mutex); \
|
||||
} \
|
||||
} else if (((policy)&BUFFER_PUSH_OVERWRITE) == 0 \
|
||||
&& CAT3(buffer_, name, _full_p)(v)) \
|
||||
&& M_C3(buffer_, name, _full_p)(v)) \
|
||||
return false; \
|
||||
\
|
||||
if (((policy)&BUFFER_PUSH_OVERWRITE) != 0 \
|
||||
@@ -198,18 +198,18 @@ static inline void \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(buffer_, name, _pop)(type *data, CAT3(buffer_, name,_t) v) \
|
||||
M_C3(buffer_, name, _pop)(type *data, M_C3(buffer_, name,_t) v) \
|
||||
{ \
|
||||
if (((policy) & BUFFER_THREAD_UNSAFE) != BUFFER_THREAD_UNSAFE) { \
|
||||
M_MUTEX_LOCK(v->mutex); \
|
||||
while (CAT3(buffer_, name, _empty_p)(v)) { \
|
||||
while (M_C3(buffer_, name, _empty_p)(v)) { \
|
||||
if (((policy) & BUFFER_UNBLOCKING) == BUFFER_UNBLOCKING) { \
|
||||
M_MUTEX_UNLOCK(v->mutex); \
|
||||
return false; \
|
||||
} \
|
||||
M_COND_WAIT(v->there_is_data, v->mutex); \
|
||||
} \
|
||||
} else if (CAT3(buffer_, name, _empty_p)(v)) \
|
||||
} else if (M_C3(buffer_, name, _empty_p)(v)) \
|
||||
return false; \
|
||||
\
|
||||
if (((policy) & BUFFER_STACK) != BUFFER_STACK) { \
|
||||
|
||||
@@ -28,8 +28,6 @@
|
||||
#include <stddef.h>
|
||||
#include <assert.h>
|
||||
|
||||
//TODO: Prefix all macros with "M_" prefix.
|
||||
|
||||
/***************************************************************/
|
||||
/************************ Compiler Macro ***********************/
|
||||
/***************************************************************/
|
||||
@@ -65,17 +63,17 @@
|
||||
#define M_MAX_NB_ARGUMENT 26
|
||||
|
||||
/* Basic handling of concatenation of symbols:
|
||||
* CAT, CAT3, CAT4
|
||||
* M_C, M_C3, M_C4
|
||||
*/
|
||||
#define CAT0(a, ...) a ## __VA_ARGS__
|
||||
#define CAT(a, ...) CAT0(a, __VA_ARGS__)
|
||||
#define CAT3_0(a, b, ...) a ## b ## __VA_ARGS__
|
||||
#define CAT3(a, b, ...) CAT3_0(a ,b, __VA_ARGS__)
|
||||
#define CAT4_0(a, b, c, ...) a ## b ## c ## __VA_ARGS__
|
||||
#define CAT4(a, b, c, ...) CAT4_0(a ,b, c, __VA_ARGS__)
|
||||
#define M_C2I(a, ...) a ## __VA_ARGS__
|
||||
#define M_C(a, ...) M_C2I(a, __VA_ARGS__)
|
||||
#define M_C3I(a, b, ...) a ## b ## __VA_ARGS__
|
||||
#define M_C3(a, b, ...) M_C3I(a ,b, __VA_ARGS__)
|
||||
#define M_C4I(a, b, c, ...) a ## b ## c ## __VA_ARGS__
|
||||
#define M_C4(a, b, c, ...) M_C4I(a ,b, c, __VA_ARGS__)
|
||||
|
||||
/* Increment the number given in argument (from [0..29[) */
|
||||
#define M_INC(x) CAT(M_INC_, x)
|
||||
#define M_INC(x) M_C(M_INC_, x)
|
||||
#define M_INC_0 1
|
||||
#define M_INC_1 2
|
||||
#define M_INC_2 3
|
||||
@@ -108,7 +106,7 @@
|
||||
#define M_INC_29 OVERFLOW
|
||||
|
||||
/* Decrement the number given in argument (from [0..29[) */
|
||||
#define M_DEC(x) CAT(M_DEC_, x)
|
||||
#define M_DEC(x) M_C(M_DEC_, x)
|
||||
#define M_DEC_0 overflow
|
||||
#define M_DEC_1 0
|
||||
#define M_DEC_2 1
|
||||
@@ -162,34 +160,33 @@
|
||||
/* Convert an integer or a symbol into 0 (if 0) or 1 (if not 0).
|
||||
1 if symbol unknown */
|
||||
#define M_TOBOOL_0 1, 0,
|
||||
#define M_BOOL(x) M_RET_ARG2(CAT(M_TOBOOL_, x), 1, useless)
|
||||
#define M_BOOL(x) M_RET_ARG2(M_C(M_TOBOOL_, x), 1, useless)
|
||||
|
||||
/* Inverse 0 into 1 and 1 into 0 */
|
||||
#define M_INV_0 1
|
||||
#define M_INV_1 0
|
||||
#define M_INV(x) CAT(M_INV_, x)
|
||||
#define M_INV(x) M_C(M_INV_, x)
|
||||
|
||||
/* Perform a AND between the inputs */
|
||||
#define M_AND_00 0
|
||||
#define M_AND_01 0
|
||||
#define M_AND_10 0
|
||||
#define M_AND_11 1
|
||||
#define M_AND(x,y) CAT3(M_AND_, x, y)
|
||||
#define M_AND(x,y) M_C3(M_AND_, x, y)
|
||||
|
||||
/* Perform a OR between the inputs */
|
||||
#define M_OR_00 0
|
||||
#define M_OR_01 1
|
||||
#define M_OR_10 1
|
||||
#define M_OR_11 1
|
||||
#define M_OR(x,y) CAT3(M_OR_, x, y)
|
||||
#define M_OR(x,y) M_C3(M_OR_, x, y)
|
||||
|
||||
/* M_IF Macro :
|
||||
M_IF(42)(Execute if true, execute if false)
|
||||
Example: M_IF(0)(true_action, false_action) --> false_action */
|
||||
#define M_IF_CAT(c) CAT(M_IF_, c)
|
||||
#define M_IF_0(true_macro, ...) __VA_ARGS__
|
||||
#define M_IF_1(true_macro, ...) true_macro
|
||||
#define M_IF(c) M_IF_CAT(M_BOOL(c))
|
||||
#define M_IF(c) M_C(M_IF_, M_BOOL(c))
|
||||
|
||||
/* Return 1 if comma inside the argument list, 0 otherwise */
|
||||
#define M_COMMA_P(...) M_RET_ARG27(__VA_ARGS__, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, useless)
|
||||
@@ -377,7 +374,7 @@
|
||||
/* If NDEBUG macro is defined
|
||||
M_IF_DEBUG(code if NDEBUG is not defined)
|
||||
Note: not 100% robust */
|
||||
#define M_TEST_NDEBUG_P() CAT3(M_, NDEBUG, _TEST)
|
||||
#define M_TEST_NDEBUG_P() M_C3(M_, NDEBUG, _TEST)
|
||||
#define M_NDEBUG_TEST 0
|
||||
#define M_IF_DEBUG(a) M_IF(M_TEST_NDEBUG_P())(,a)
|
||||
|
||||
@@ -414,7 +411,7 @@
|
||||
#define M_NOTEQUAL_27_27 0
|
||||
#define M_NOTEQUAL_28_28 0
|
||||
#define M_NOTEQUAL_29_29 0
|
||||
#define M_NOTEQUAL(x,y) M_BOOL(CAT4(M_NOTEQUAL_, x, _, y))
|
||||
#define M_NOTEQUAL(x,y) M_BOOL(M_C4(M_NOTEQUAL_, x, _, y))
|
||||
|
||||
/* ADD: Through recursivity.
|
||||
Example: ADD(4,5) --> 9 */
|
||||
@@ -480,7 +477,7 @@
|
||||
(_25,_24,_23,_22,_21,_20,_19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1)
|
||||
#define M_INVERT_26(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,_21,_22,_23,_24,_25,_26)\
|
||||
(_26,_25,_24,_23,_22,_21,_20,_19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1)
|
||||
#define M_INVERT(...) CAT(M_INVERT_, M_NARGS(__VA_ARGS__))(__VA_ARGS__)
|
||||
#define M_INVERT(...) M_C(M_INVERT_, M_NARGS(__VA_ARGS__))(__VA_ARGS__)
|
||||
|
||||
|
||||
/***************************************************************/
|
||||
@@ -589,7 +586,7 @@
|
||||
M_GET_METHOD(INIT, my_default, INIT(mpz_init),CLEAR(mpz_clear),SET(mpz_set)) --> mpz_init
|
||||
M_GET_METHOD(INIT, my_default, CLEAR(mpz_clear),SET(mpz_set)) --> my_default */
|
||||
#define M_GET_METHOD(method, method_default, ...) \
|
||||
M_RET_ARG2 (M_MAP2B(CAT, CAT3(M_, method, _), __VA_ARGS__), method_default,)
|
||||
M_RET_ARG2 (M_MAP2B(M_C, M_C3(M_, method, _), __VA_ARGS__), method_default,)
|
||||
|
||||
/* Get the given method */
|
||||
#define M_GET_INIT(...) M_GET_METHOD(INIT, M_INIT_DEFAULT, __VA_ARGS__)
|
||||
@@ -704,8 +701,8 @@ m_core_hash(const void *ptr, size_t s)
|
||||
First argument will be a created pointer to the underlying type.
|
||||
Example: for M_EACH(item, list, LIST_OPLIST) { action; } */
|
||||
#define M_EACH(item, container, oplist) \
|
||||
M_EACHI(item, container, oplist, CAT(local_iterator_, __LINE__), \
|
||||
CAT(local_cont_, __LINE__))
|
||||
M_EACHI(item, container, oplist, M_C(local_iterator_, __LINE__), \
|
||||
M_C(local_cont_, __LINE__))
|
||||
|
||||
/* Internal for M_EACH */
|
||||
#define M_EACHI(item,container,oplist, iterator, cont) \
|
||||
@@ -722,7 +719,7 @@ m_core_hash(const void *ptr, size_t s)
|
||||
M_LET(a, STRING_OPLIST) { do something with a } or
|
||||
M_LET(a, b, c, STRING_OPLIST) { do something with a, b & c } */
|
||||
#define M_LET(...) \
|
||||
M_ID(M_LETI M_INVERT( __VA_ARGS__, CAT(local_cont_, __LINE__) ))
|
||||
M_ID(M_LETI M_INVERT( __VA_ARGS__, M_C(local_cont_, __LINE__) ))
|
||||
|
||||
#define M_LETI(cont, oplist, ...) \
|
||||
for(bool cont = true; cont ; cont = false) \
|
||||
|
||||
@@ -32,111 +32,111 @@
|
||||
|
||||
/* Define a dictionnary with the key key_type to the value value_type. */
|
||||
#define DICT_DEF2(name, key_type, key_oplist, value_type, value_oplist) \
|
||||
TUPLE_DEF2(CAT(dict_pair_, name), (key, key_type, key_oplist), (value, value_type, value_oplist)) \
|
||||
LIST_DEF(CAT(dict_pair_, name), CAT3(dict_pair_,name,_t), TUPLE_OPLIST(CAT(dict_pair_, name), key_oplist, value_oplist)) \
|
||||
ARRAY_DEF(CAT(list_dict_pair_,name), CAT3(list_dict_pair_,name,_t), LIST_OPLIST(CAT(dict_pair_, name))) \
|
||||
TUPLE_DEF2(M_C(dict_pair_, name), (key, key_type, key_oplist), (value, value_type, value_oplist)) \
|
||||
LIST_DEF(M_C(dict_pair_, name), M_C3(dict_pair_,name,_t), TUPLE_OPLIST(M_C(dict_pair_, name), key_oplist, value_oplist)) \
|
||||
ARRAY_DEF(M_C(list_dict_pair_,name), M_C3(list_dict_pair_,name,_t), LIST_OPLIST(M_C(dict_pair_, name))) \
|
||||
\
|
||||
typedef struct CAT3(dict_, name, _s) { \
|
||||
typedef struct M_C3(dict_, name, _s) { \
|
||||
size_t used, lower_limit, upper_limit; \
|
||||
CAT3(array_list_dict_pair_,name,_t) table; \
|
||||
} CAT3(dict_, name, _t)[1]; \
|
||||
M_C3(array_list_dict_pair_,name,_t) table; \
|
||||
} M_C3(dict_, name, _t)[1]; \
|
||||
\
|
||||
typedef struct CAT3(dict_it_, name, _s) { \
|
||||
CAT3(array_it_list_dict_pair_, name, _t) array_it; \
|
||||
CAT3(list_it_dict_pair_, name, _t) list_it; \
|
||||
} CAT3(dict_it_, name, _t)[1]; \
|
||||
typedef struct M_C3(dict_it_, name, _s) { \
|
||||
M_C3(array_it_list_dict_pair_, name, _t) array_it; \
|
||||
M_C3(list_it_dict_pair_, name, _t) list_it; \
|
||||
} M_C3(dict_it_, name, _t)[1]; \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_, name, _init)(CAT3(dict_,name,_t) map) \
|
||||
M_C3(dict_, name, _init)(M_C3(dict_,name,_t) map) \
|
||||
{ \
|
||||
map->used = 0; \
|
||||
CAT3(array_list_dict_pair_,name,_init)(map->table); \
|
||||
CAT3(array_list_dict_pair_,name,_resize)(map->table, DICTI_INITIAL_SIZE); \
|
||||
M_C3(array_list_dict_pair_,name,_init)(map->table); \
|
||||
M_C3(array_list_dict_pair_,name,_resize)(map->table, DICTI_INITIAL_SIZE); \
|
||||
map->lower_limit = DICTI_LOWER_BOUND(DICTI_INITIAL_SIZE); \
|
||||
map->upper_limit = DICTI_UPPER_BOUND(DICTI_INITIAL_SIZE); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_, name, _init_set)(CAT3(dict_,name,_t) map, \
|
||||
const CAT3(dict_,name,_t) org) \
|
||||
M_C3(dict_, name, _init_set)(M_C3(dict_,name,_t) map, \
|
||||
const M_C3(dict_,name,_t) org) \
|
||||
{ \
|
||||
DICTI_CONTRACT(name, org); \
|
||||
map->used = org->used; \
|
||||
map->lower_limit = org->lower_limit; \
|
||||
map->upper_limit = org->upper_limit; \
|
||||
CAT3(array_list_dict_pair_,name,_init_set)(map->table, org->table); \
|
||||
M_C3(array_list_dict_pair_,name,_init_set)(map->table, org->table); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_, name, _set)(CAT3(dict_,name,_t) map, \
|
||||
const CAT3(dict_,name,_t) org) \
|
||||
M_C3(dict_, name, _set)(M_C3(dict_,name,_t) map, \
|
||||
const M_C3(dict_,name,_t) org) \
|
||||
{ \
|
||||
DICTI_CONTRACT(name, map); \
|
||||
DICTI_CONTRACT(name, org); \
|
||||
map->used = org->used; \
|
||||
map->lower_limit = org->lower_limit; \
|
||||
map->upper_limit = org->upper_limit; \
|
||||
CAT3(array_list_dict_pair_,name,_set)(map->table, org->table); \
|
||||
M_C3(array_list_dict_pair_,name,_set)(map->table, org->table); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_,name,_clear)(CAT3(dict_,name,_t) map) \
|
||||
M_C3(dict_,name,_clear)(M_C3(dict_,name,_t) map) \
|
||||
{ \
|
||||
CAT3(array_list_dict_pair_,name,_clear)(map->table); \
|
||||
M_C3(array_list_dict_pair_,name,_clear)(map->table); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_, name, _init_move)(CAT3(dict_,name,_t) map, \
|
||||
CAT3(dict_,name,_t) org) \
|
||||
M_C3(dict_, name, _init_move)(M_C3(dict_,name,_t) map, \
|
||||
M_C3(dict_,name,_t) org) \
|
||||
{ \
|
||||
DICTI_CONTRACT(name, org); \
|
||||
map->used = org->used; \
|
||||
map->lower_limit = org->lower_limit; \
|
||||
map->upper_limit = org->upper_limit; \
|
||||
CAT3(array_list_dict_pair_,name,_init_move)(map->table, org->table); \
|
||||
M_C3(array_list_dict_pair_,name,_init_move)(map->table, org->table); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_, name, _move)(CAT3(dict_,name,_t) map, \
|
||||
CAT3(dict_,name,_t) org) \
|
||||
M_C3(dict_, name, _move)(M_C3(dict_,name,_t) map, \
|
||||
M_C3(dict_,name,_t) org) \
|
||||
{ \
|
||||
DICTI_CONTRACT(name, map); \
|
||||
DICTI_CONTRACT(name, org); \
|
||||
assert (map != org); \
|
||||
CAT3(dict_,name,_clear)(map); \
|
||||
CAT3(dict_,name,_init_move)(map, org); \
|
||||
M_C3(dict_,name,_clear)(map); \
|
||||
M_C3(dict_,name,_init_move)(map, org); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_,name,_clean)(CAT3(dict_,name,_t) map) \
|
||||
M_C3(dict_,name,_clean)(M_C3(dict_,name,_t) map) \
|
||||
{ \
|
||||
CAT3(array_list_dict_pair_,name,_clean)(map->table); \
|
||||
CAT3(array_list_dict_pair_,name,_resize)(map->table, DICTI_INITIAL_SIZE); \
|
||||
M_C3(array_list_dict_pair_,name,_clean)(map->table); \
|
||||
M_C3(array_list_dict_pair_,name,_resize)(map->table, DICTI_INITIAL_SIZE); \
|
||||
map->lower_limit = DICTI_LOWER_BOUND(DICTI_INITIAL_SIZE); \
|
||||
map->upper_limit = DICTI_UPPER_BOUND(DICTI_INITIAL_SIZE); \
|
||||
map->used = 0; \
|
||||
} \
|
||||
\
|
||||
static inline size_t \
|
||||
CAT3(dict_,name,_size)(const CAT3(dict_,name,_t) map) \
|
||||
M_C3(dict_,name,_size)(const M_C3(dict_,name,_t) map) \
|
||||
{ \
|
||||
DICTI_CONTRACT(name, map); \
|
||||
return map->used; \
|
||||
} \
|
||||
\
|
||||
static inline value_type * \
|
||||
CAT3(dict_,name,_get)(const CAT3(dict_,name,_t) map, const key_type key) \
|
||||
M_C3(dict_,name,_get)(const M_C3(dict_,name,_t) map, const key_type key) \
|
||||
{ \
|
||||
DICTI_CONTRACT(name, map); \
|
||||
size_t hash = M_GET_HASH key_oplist (key); \
|
||||
hash = hash & (CAT3(array_list_dict_pair_,name,_size)(map->table) - 1); \
|
||||
const CAT3(list_dict_pair_,name,_t) *list_ptr = \
|
||||
CAT3(array_list_dict_pair_,name,_cget)(map->table, hash); \
|
||||
CAT3(list_it_dict_pair_,name,_t) it; \
|
||||
for(CAT3(list_dict_pair_,name,_it)(it, *list_ptr); \
|
||||
!CAT3(list_dict_pair_,name,_end_p)(it); \
|
||||
CAT3(list_dict_pair_,name,_next)(it)) { \
|
||||
CAT3(dict_pair_,name,_t) *ref = CAT3(list_dict_pair_,name,_ref)(it); \
|
||||
hash = hash & (M_C3(array_list_dict_pair_,name,_size)(map->table) - 1); \
|
||||
const M_C3(list_dict_pair_,name,_t) *list_ptr = \
|
||||
M_C3(array_list_dict_pair_,name,_cget)(map->table, hash); \
|
||||
M_C3(list_it_dict_pair_,name,_t) it; \
|
||||
for(M_C3(list_dict_pair_,name,_it)(it, *list_ptr); \
|
||||
!M_C3(list_dict_pair_,name,_end_p)(it); \
|
||||
M_C3(list_dict_pair_,name,_next)(it)) { \
|
||||
M_C3(dict_pair_,name,_t) *ref = M_C3(list_dict_pair_,name,_ref)(it); \
|
||||
if (M_GET_EQUAL key_oplist ((*ref)->key, key)) \
|
||||
return &(*ref)->value; \
|
||||
} \
|
||||
@@ -144,30 +144,30 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dicti_,name,_resize_up)(CAT3(dict_,name,_t) map) \
|
||||
M_C3(dicti_,name,_resize_up)(M_C3(dict_,name,_t) map) \
|
||||
{ \
|
||||
size_t old_size = CAT3(array_list_dict_pair_,name,_size)(map->table); \
|
||||
size_t old_size = M_C3(array_list_dict_pair_,name,_size)(map->table); \
|
||||
size_t new_size = old_size * 2; \
|
||||
/* Resize the dictionnary */ \
|
||||
CAT3(array_list_dict_pair_,name,_resize)(map->table, new_size); \
|
||||
M_C3(array_list_dict_pair_,name,_resize)(map->table, new_size); \
|
||||
/* Move the items to the new upper part */ \
|
||||
for(size_t i = 0; i < old_size; i++) { \
|
||||
CAT3(list_dict_pair_,name,_t) *list = \
|
||||
CAT3(array_list_dict_pair_,name,_get)(map->table, i); \
|
||||
if (CAT3(list_dict_pair_,name,_empty_p)(*list)) \
|
||||
M_C3(list_dict_pair_,name,_t) *list = \
|
||||
M_C3(array_list_dict_pair_,name,_get)(map->table, i); \
|
||||
if (M_C3(list_dict_pair_,name,_empty_p)(*list)) \
|
||||
continue; \
|
||||
CAT3(list_it_dict_pair_,name,_t) it; \
|
||||
CAT3(list_dict_pair_,name,_it)(it, *list); \
|
||||
while (!CAT3(list_dict_pair_,name,_end_p)(it)) { \
|
||||
CAT3(dict_pair_,name,_ptr) pair = *CAT3(list_dict_pair_,name,_ref)(it); \
|
||||
M_C3(list_it_dict_pair_,name,_t) it; \
|
||||
M_C3(list_dict_pair_,name,_it)(it, *list); \
|
||||
while (!M_C3(list_dict_pair_,name,_end_p)(it)) { \
|
||||
M_C3(dict_pair_,name,_ptr) pair = *M_C3(list_dict_pair_,name,_ref)(it); \
|
||||
size_t hash = M_GET_HASH key_oplist (pair->key); \
|
||||
if ((hash & (new_size-1)) >= old_size) { \
|
||||
assert( (hash & (new_size-1)) == (i + old_size)); \
|
||||
CAT3(list_dict_pair_,name,_t) *new_list = \
|
||||
CAT3(array_list_dict_pair_,name,_get)(map->table, i + old_size); \
|
||||
CAT3(list_dict_pair_,name,_move_back)(*new_list, *list, it); \
|
||||
M_C3(list_dict_pair_,name,_t) *new_list = \
|
||||
M_C3(array_list_dict_pair_,name,_get)(map->table, i + old_size); \
|
||||
M_C3(list_dict_pair_,name,_move_back)(*new_list, *list, it); \
|
||||
} else { \
|
||||
CAT3(list_dict_pair_,name,_next)(it); \
|
||||
M_C3(list_dict_pair_,name,_next)(it); \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
@@ -176,191 +176,191 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dicti_,name,_resize_down)(CAT3(dict_,name,_t) map) \
|
||||
M_C3(dicti_,name,_resize_down)(M_C3(dict_,name,_t) map) \
|
||||
{ \
|
||||
assert (map != NULL); \
|
||||
size_t old_size = CAT3(array_list_dict_pair_,name,_size)(map->table); \
|
||||
size_t old_size = M_C3(array_list_dict_pair_,name,_size)(map->table); \
|
||||
assert ((old_size % 2) == 0); \
|
||||
size_t new_size = old_size / 2; \
|
||||
assert (new_size >= DICTI_INITIAL_SIZE); \
|
||||
/* Move all items to the lower part of the dictionnary */ \
|
||||
for(size_t i = new_size; i < old_size; i++) { \
|
||||
CAT3(list_dict_pair_,name,_t) *list = \
|
||||
CAT3(array_list_dict_pair_,name,_get)(map->table, i); \
|
||||
if (CAT3(list_dict_pair_,name,_empty_p)(*list)) \
|
||||
M_C3(list_dict_pair_,name,_t) *list = \
|
||||
M_C3(array_list_dict_pair_,name,_get)(map->table, i); \
|
||||
if (M_C3(list_dict_pair_,name,_empty_p)(*list)) \
|
||||
continue; \
|
||||
CAT3(list_it_dict_pair_,name,_t) it; \
|
||||
CAT3(list_dict_pair_,name,_it)(it, *list); \
|
||||
while (!CAT3(list_dict_pair_,name,_end_p)(it)) { \
|
||||
M_IF_DEBUG(CAT3(dict_pair_,name,_ptr) pair = *CAT3(list_dict_pair_,name,_ref)(it);) \
|
||||
M_C3(list_it_dict_pair_,name,_t) it; \
|
||||
M_C3(list_dict_pair_,name,_it)(it, *list); \
|
||||
while (!M_C3(list_dict_pair_,name,_end_p)(it)) { \
|
||||
M_IF_DEBUG(M_C3(dict_pair_,name,_ptr) pair = *M_C3(list_dict_pair_,name,_ref)(it);) \
|
||||
M_IF_DEBUG(size_t hash = M_GET_HASH key_oplist (pair->key);) \
|
||||
assert ((hash & (old_size -1)) == i); \
|
||||
assert ((hash & (new_size -1)) == i - new_size); \
|
||||
CAT3(list_dict_pair_,name,_t) *new_list = \
|
||||
CAT3(array_list_dict_pair_,name,_get)(map->table, i - new_size); \
|
||||
CAT3(list_dict_pair_,name,_move_back)(*new_list, *list, it); \
|
||||
M_C3(list_dict_pair_,name,_t) *new_list = \
|
||||
M_C3(array_list_dict_pair_,name,_get)(map->table, i - new_size); \
|
||||
M_C3(list_dict_pair_,name,_move_back)(*new_list, *list, it); \
|
||||
} \
|
||||
} \
|
||||
/* Resize the dictionary */ \
|
||||
CAT3(array_list_dict_pair_,name,_resize)(map->table, new_size); \
|
||||
M_C3(array_list_dict_pair_,name,_resize)(map->table, new_size); \
|
||||
map->upper_limit = DICTI_UPPER_BOUND(new_size); \
|
||||
map->lower_limit = DICTI_LOWER_BOUND(new_size); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_,name,_set_at)(CAT3(dict_,name,_t) map, \
|
||||
M_C3(dict_,name,_set_at)(M_C3(dict_,name,_t) map, \
|
||||
const key_type key, const value_type value) \
|
||||
{ \
|
||||
DICTI_CONTRACT(name, map); \
|
||||
\
|
||||
size_t hash = M_GET_HASH key_oplist(key); \
|
||||
hash = hash & (CAT3(array_list_dict_pair_,name,_size)(map->table) - 1); \
|
||||
CAT3(list_dict_pair_,name,_t) *list_ptr = \
|
||||
CAT3(array_list_dict_pair_,name,_get)(map->table, hash); \
|
||||
CAT3(list_it_dict_pair_,name,_t) it; \
|
||||
for(CAT3(list_dict_pair_,name,_it)(it, *list_ptr); \
|
||||
!CAT3(list_dict_pair_,name,_end_p)(it); \
|
||||
CAT3(list_dict_pair_,name,_next)(it)) { \
|
||||
CAT3(dict_pair_,name,_ptr) ref = *CAT3(list_dict_pair_,name,_ref)(it); \
|
||||
hash = hash & (M_C3(array_list_dict_pair_,name,_size)(map->table) - 1); \
|
||||
M_C3(list_dict_pair_,name,_t) *list_ptr = \
|
||||
M_C3(array_list_dict_pair_,name,_get)(map->table, hash); \
|
||||
M_C3(list_it_dict_pair_,name,_t) it; \
|
||||
for(M_C3(list_dict_pair_,name,_it)(it, *list_ptr); \
|
||||
!M_C3(list_dict_pair_,name,_end_p)(it); \
|
||||
M_C3(list_dict_pair_,name,_next)(it)) { \
|
||||
M_C3(dict_pair_,name,_ptr) ref = *M_C3(list_dict_pair_,name,_ref)(it); \
|
||||
if (M_GET_EQUAL key_oplist(ref->key, key)) { \
|
||||
M_GET_SET value_oplist(ref->value, value); \
|
||||
return; \
|
||||
} \
|
||||
} \
|
||||
CAT3(dict_pair_,name,_init_set2)(*CAT3(list_dict_pair_,name,_push_raw)(*list_ptr), \
|
||||
M_C3(dict_pair_,name,_init_set2)(*M_C3(list_dict_pair_,name,_push_raw)(*list_ptr), \
|
||||
key, value); \
|
||||
map->used ++; \
|
||||
if (map->used > map->upper_limit) \
|
||||
CAT3(dicti_,name,_resize_up)(map); \
|
||||
M_C3(dicti_,name,_resize_up)(map); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_,name,_remove)(CAT3(dict_,name,_t) map, const key_type key) \
|
||||
M_C3(dict_,name,_remove)(M_C3(dict_,name,_t) map, const key_type key) \
|
||||
{ \
|
||||
DICTI_CONTRACT(name, map); \
|
||||
\
|
||||
size_t hash = M_GET_HASH key_oplist(key); \
|
||||
hash = hash & (CAT3(array_list_dict_pair_,name,_size)(map->table) - 1); \
|
||||
CAT3(list_dict_pair_,name,_t) *list_ptr = \
|
||||
CAT3(array_list_dict_pair_,name,_get)(map->table, hash); \
|
||||
CAT3(list_it_dict_pair_,name,_t) it; \
|
||||
for(CAT3(list_dict_pair_,name,_it)(it, *list_ptr); \
|
||||
!CAT3(list_dict_pair_,name,_end_p)(it); \
|
||||
CAT3(list_dict_pair_,name,_next)(it)) { \
|
||||
CAT3(dict_pair_,name,_ptr) ref = *CAT3(list_dict_pair_,name,_ref)(it); \
|
||||
hash = hash & (M_C3(array_list_dict_pair_,name,_size)(map->table) - 1); \
|
||||
M_C3(list_dict_pair_,name,_t) *list_ptr = \
|
||||
M_C3(array_list_dict_pair_,name,_get)(map->table, hash); \
|
||||
M_C3(list_it_dict_pair_,name,_t) it; \
|
||||
for(M_C3(list_dict_pair_,name,_it)(it, *list_ptr); \
|
||||
!M_C3(list_dict_pair_,name,_end_p)(it); \
|
||||
M_C3(list_dict_pair_,name,_next)(it)) { \
|
||||
M_C3(dict_pair_,name,_ptr) ref = *M_C3(list_dict_pair_,name,_ref)(it); \
|
||||
if (M_GET_EQUAL key_oplist(ref->key, key)) { \
|
||||
CAT3(list_dict_pair_,name,_remove)(*list_ptr, it); \
|
||||
M_C3(list_dict_pair_,name,_remove)(*list_ptr, it); \
|
||||
map->used --; \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
if (map->used < map->lower_limit) \
|
||||
CAT3(dicti_, name, _resize_down)(map); \
|
||||
M_C3(dicti_, name, _resize_down)(map); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_, name, _it)(CAT3(dict_it_, name,_t) it, \
|
||||
CAT3(dict_, name,_t) d) \
|
||||
M_C3(dict_, name, _it)(M_C3(dict_it_, name,_t) it, \
|
||||
M_C3(dict_, name,_t) d) \
|
||||
{ \
|
||||
CAT3(array_list_dict_pair_, name, _it)(it->array_it, d->table); \
|
||||
CAT3(list_dict_pair_,name,_t) *ref = \
|
||||
CAT3(array_list_dict_pair_, name, _ref)(it->array_it); \
|
||||
CAT3(list_dict_pair_, name, _it)(it->list_it, *ref); \
|
||||
while (CAT3(list_dict_pair_, name, _end_p)(it->list_it)) { \
|
||||
CAT3(array_list_dict_pair_, name, _next)(it->array_it); \
|
||||
if (CAT3(array_list_dict_pair_, name, _end_p)(it->array_it))break; \
|
||||
ref = CAT3(array_list_dict_pair_, name, _ref)(it->array_it); \
|
||||
CAT3(list_dict_pair_, name, _it)(it->list_it, *ref); \
|
||||
M_C3(array_list_dict_pair_, name, _it)(it->array_it, d->table); \
|
||||
M_C3(list_dict_pair_,name,_t) *ref = \
|
||||
M_C3(array_list_dict_pair_, name, _ref)(it->array_it); \
|
||||
M_C3(list_dict_pair_, name, _it)(it->list_it, *ref); \
|
||||
while (M_C3(list_dict_pair_, name, _end_p)(it->list_it)) { \
|
||||
M_C3(array_list_dict_pair_, name, _next)(it->array_it); \
|
||||
if (M_C3(array_list_dict_pair_, name, _end_p)(it->array_it))break; \
|
||||
ref = M_C3(array_list_dict_pair_, name, _ref)(it->array_it); \
|
||||
M_C3(list_dict_pair_, name, _it)(it->list_it, *ref); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_, name, _it_set)(CAT3(dict_it_, name,_t) it, \
|
||||
const CAT3(dict_it_, name,_t) ref) \
|
||||
M_C3(dict_, name, _it_set)(M_C3(dict_it_, name,_t) it, \
|
||||
const M_C3(dict_it_, name,_t) ref) \
|
||||
{ \
|
||||
assert (it != NULL && ref != NULL); \
|
||||
CAT3(array_list_dict_pair_, name, _it_set)(it->array_it, \
|
||||
M_C3(array_list_dict_pair_, name, _it_set)(it->array_it, \
|
||||
ref->array_it); \
|
||||
CAT3(list_dict_pair_, name, _it_set)(it->list_it, ref->list_it); \
|
||||
M_C3(list_dict_pair_, name, _it_set)(it->list_it, ref->list_it); \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(dict_, name, _end_p)(const CAT3(dict_it_, name,_t) it) \
|
||||
M_C3(dict_, name, _end_p)(const M_C3(dict_it_, name,_t) it) \
|
||||
{ \
|
||||
assert (it != NULL); \
|
||||
return CAT3(list_dict_pair_, name, _end_p)(it->list_it); \
|
||||
return M_C3(list_dict_pair_, name, _end_p)(it->list_it); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(dict_, name, _next)(CAT3(dict_it_, name,_t) it) \
|
||||
M_C3(dict_, name, _next)(M_C3(dict_it_, name,_t) it) \
|
||||
{ \
|
||||
assert(it != NULL); \
|
||||
CAT3(list_dict_pair_, name, _next)(it->list_it); \
|
||||
CAT3(list_dict_pair_,name,_t) *ref; \
|
||||
while (CAT3(list_dict_pair_, name, _end_p)(it->list_it)) { \
|
||||
CAT3(array_list_dict_pair_, name, _next)(it->array_it); \
|
||||
if (CAT3(array_list_dict_pair_, name, _end_p)(it->array_it))break; \
|
||||
ref = CAT3(array_list_dict_pair_, name, _ref)(it->array_it); \
|
||||
CAT3(list_dict_pair_, name, _it)(it->list_it, *ref); \
|
||||
M_C3(list_dict_pair_, name, _next)(it->list_it); \
|
||||
M_C3(list_dict_pair_,name,_t) *ref; \
|
||||
while (M_C3(list_dict_pair_, name, _end_p)(it->list_it)) { \
|
||||
M_C3(array_list_dict_pair_, name, _next)(it->array_it); \
|
||||
if (M_C3(array_list_dict_pair_, name, _end_p)(it->array_it))break; \
|
||||
ref = M_C3(array_list_dict_pair_, name, _ref)(it->array_it); \
|
||||
M_C3(list_dict_pair_, name, _it)(it->list_it, *ref); \
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(dict_, name, _last_p)(const CAT3(dict_it_, name,_t) it) \
|
||||
M_C3(dict_, name, _last_p)(const M_C3(dict_it_, name,_t) it) \
|
||||
{ \
|
||||
assert (it != NULL); \
|
||||
CAT3(dict_it_, name,_t) it2; \
|
||||
CAT3(dict_, name,_it_set)(it2, it); \
|
||||
CAT3(dict_, name, _next)(it2); \
|
||||
return CAT3(dict_, name, _end_p)(it2); \
|
||||
M_C3(dict_it_, name,_t) it2; \
|
||||
M_C3(dict_, name,_it_set)(it2, it); \
|
||||
M_C3(dict_, name, _next)(it2); \
|
||||
return M_C3(dict_, name, _end_p)(it2); \
|
||||
} \
|
||||
\
|
||||
static inline CAT3(dict_pair_,name,_t) * \
|
||||
CAT3(dict_, name, _ref)(CAT3(dict_it_, name,_t) it) \
|
||||
static inline M_C3(dict_pair_,name,_t) * \
|
||||
M_C3(dict_, name, _ref)(M_C3(dict_it_, name,_t) it) \
|
||||
{ \
|
||||
assert(it != NULL); \
|
||||
return CAT3(list_dict_pair_, name, _ref)(it->list_it); \
|
||||
return M_C3(list_dict_pair_, name, _ref)(it->list_it); \
|
||||
} \
|
||||
\
|
||||
static inline const CAT3(dict_pair_,name,_t) * \
|
||||
CAT3(dict_, name, _cref)(const CAT3(dict_it_, name,_t) it) \
|
||||
static inline const M_C3(dict_pair_,name,_t) * \
|
||||
M_C3(dict_, name, _cref)(const M_C3(dict_it_, name,_t) it) \
|
||||
{ \
|
||||
assert(it != NULL); \
|
||||
return CAT3(list_dict_pair_, name, _cref)(it->list_it); \
|
||||
return M_C3(list_dict_pair_, name, _cref)(it->list_it); \
|
||||
} \
|
||||
\
|
||||
M_IF_METHOD(EQUAL, value_oplist)( \
|
||||
static inline bool \
|
||||
CAT3(dict_, name, _equal_p)(CAT3(dict_, name,_t) dict1, \
|
||||
CAT3(dict_, name,_t) dict2) \
|
||||
M_C3(dict_, name, _equal_p)(M_C3(dict_, name,_t) dict1, \
|
||||
M_C3(dict_, name,_t) dict2) \
|
||||
{ \
|
||||
assert (dict1 != NULL && dict2 != NULL); \
|
||||
/* NOTE: Key type has mandatory equal operator */ \
|
||||
return dict1->used == dict2-> used && \
|
||||
CAT3(array_list_dict_pair_, name, _equal_p)(dict1->table, \
|
||||
M_C3(array_list_dict_pair_, name, _equal_p)(dict1->table, \
|
||||
dict2->table); \
|
||||
} \
|
||||
, /* no value equal */ ) \
|
||||
\
|
||||
M_IF_METHOD_BOTH(GET_STR, key_oplist, value_oplist)( \
|
||||
static inline void \
|
||||
CAT3(dict_, name, _get_str)(string_t str, \
|
||||
CAT3(dict_, name,_t) dict, \
|
||||
M_C3(dict_, name, _get_str)(string_t str, \
|
||||
M_C3(dict_, name,_t) dict, \
|
||||
const bool append) \
|
||||
{ \
|
||||
assert (str != NULL && dict != NULL); \
|
||||
DICTI_CONTRACT(name, dict); \
|
||||
(append ? string_cat_str : string_set_str) (str, "{"); \
|
||||
CAT3(dict_it_, name, _t) it; \
|
||||
for (CAT3(dict_, name, _it)(it, dict) ; \
|
||||
!CAT3(dict_, name, _end_p)(it); \
|
||||
CAT3(dict_, name, _next)(it)){ \
|
||||
const CAT3(dict_pair_,name,_t) *item = \
|
||||
CAT3(dict_, name, _cref)(it); \
|
||||
M_C3(dict_it_, name, _t) it; \
|
||||
for (M_C3(dict_, name, _it)(it, dict) ; \
|
||||
!M_C3(dict_, name, _end_p)(it); \
|
||||
M_C3(dict_, name, _next)(it)){ \
|
||||
const M_C3(dict_pair_,name,_t) *item = \
|
||||
M_C3(dict_, name, _cref)(it); \
|
||||
M_GET_GET_STR key_oplist (str, (*item)->key, true); \
|
||||
string_push_back (str, ':'); \
|
||||
M_GET_GET_STR value_oplist (str, (*item)->value, true); \
|
||||
if (!CAT3(dict_, name, _last_p)(it)) \
|
||||
if (!M_C3(dict_, name, _last_p)(it)) \
|
||||
string_push_back (str, ','); \
|
||||
} \
|
||||
string_push_back (str, '}'); \
|
||||
@@ -369,22 +369,22 @@
|
||||
\
|
||||
M_IF_METHOD_BOTH(OUT_STR, key_oplist, value_oplist)( \
|
||||
static inline void \
|
||||
CAT3(dict_, name, _out_str)(FILE *file, \
|
||||
CAT3(dict_, name,_t) dict) \
|
||||
M_C3(dict_, name, _out_str)(FILE *file, \
|
||||
M_C3(dict_, name,_t) dict) \
|
||||
{ \
|
||||
assert (file != NULL && dict != NULL); \
|
||||
DICTI_CONTRACT(name, dict); \
|
||||
fputc ('{', file); \
|
||||
CAT3(dict_it_, name, _t) it; \
|
||||
for (CAT3(dict_, name, _it)(it, dict) ; \
|
||||
!CAT3(dict_, name, _end_p)(it); \
|
||||
CAT3(dict_, name, _next)(it)){ \
|
||||
const CAT3(dict_pair_,name,_t) *item = \
|
||||
CAT3(dict_, name, _cref)(it); \
|
||||
M_C3(dict_it_, name, _t) it; \
|
||||
for (M_C3(dict_, name, _it)(it, dict) ; \
|
||||
!M_C3(dict_, name, _end_p)(it); \
|
||||
M_C3(dict_, name, _next)(it)){ \
|
||||
const M_C3(dict_pair_,name,_t) *item = \
|
||||
M_C3(dict_, name, _cref)(it); \
|
||||
M_GET_OUT_STR key_oplist (file, (*item)->key); \
|
||||
fputc (':', file); \
|
||||
M_GET_OUT_STR value_oplist (file, (*item)->value); \
|
||||
if (!CAT3(dict_, name, _last_p)(it)) \
|
||||
if (!M_C3(dict_, name, _last_p)(it)) \
|
||||
fputc (',', file); \
|
||||
} \
|
||||
fputc ('}', file); \
|
||||
@@ -393,11 +393,11 @@
|
||||
\
|
||||
M_IF_METHOD_BOTH(IN_STR, key_oplist, value_oplist)( \
|
||||
static inline bool \
|
||||
CAT3(dict_, name, _in_str)(CAT3(dict_, name,_t) dict, FILE *file) \
|
||||
M_C3(dict_, name, _in_str)(M_C3(dict_, name,_t) dict, FILE *file) \
|
||||
{ \
|
||||
assert (file != NULL && dict != NULL); \
|
||||
DICTI_CONTRACT(name, dict); \
|
||||
CAT3(dict_, name, _clean)(dict); \
|
||||
M_C3(dict_, name, _clean)(dict); \
|
||||
char c = fgetc(file); \
|
||||
if (c != '{') return false; \
|
||||
key_type key; \
|
||||
@@ -411,7 +411,7 @@
|
||||
if (c != ':') { c = 0; break; } \
|
||||
b = M_GET_IN_STR value_oplist (value, file); \
|
||||
if (!b) { c = 0; break; } \
|
||||
CAT3(dict_, name, _set_at)(dict, key, value); \
|
||||
M_C3(dict_, name, _set_at)(dict, key, value); \
|
||||
c = fgetc(file); \
|
||||
} while (c == ',' && !feof(file) && !ferror(file)); \
|
||||
M_GET_CLEAR key_oplist (key); \
|
||||
@@ -432,26 +432,26 @@
|
||||
|
||||
/* Define the oplist of a dictionnary */
|
||||
#define DICTI_OPLIST(type, key_oplist, value_oplist) \
|
||||
(INIT(CAT3(dict_, type, _init)), \
|
||||
INIT_SET(CAT3(dict_, type, _init_set)), \
|
||||
SET(CAT3(dict_, type, _set)), \
|
||||
CLEAR(CAT3(dict_, type, _clear)), \
|
||||
INIT_MOVE(CAT3(dict_, type, _init_move)), \
|
||||
MOVE(CAT3(dict_, type, _move)), \
|
||||
TYPE(CAT3(dict_, type, _t)), \
|
||||
SUBTYPE(CAT3(dict_pair_,type,_t)), \
|
||||
IT_TYPE(CAT3(dict_it_,type,_t)), \
|
||||
IT_FIRST(CAT3(dict_,type,_it)), \
|
||||
IT_SET(CAT3(dict_, type, _it_set)), \
|
||||
IT_END_P(CAT3(dict_,type,_end_p)), \
|
||||
IT_LAST_P(CAT3(dict_,type,_last_p)), \
|
||||
IT_NEXT(CAT3(dict_,type,_next)), \
|
||||
IT_REF(CAT3(dict_,type,_ref)), \
|
||||
IT_CREF(CAT3(dict_,type,_cref)) \
|
||||
,M_IF_METHOD_BOTH(GET_STR, key_oplist, value_oplist)(GET_STR(CAT3(array_, type, _get_str)),) \
|
||||
,M_IF_METHOD_BOTH(OUT_STR, key_oplist, value_oplist)(OUT_STR(CAT3(array_, type, _out_str)),) \
|
||||
,M_IF_METHOD_BOTH(IN_STR, key_oplist, value_oplist)(IN_STR(CAT3(array_, type, _in_str)),) \
|
||||
,M_IF_METHOD(EQUAL, value_oplist)(EQUAL(CAT3(dict_, type, _equal_p)),) \
|
||||
(INIT(M_C3(dict_, type, _init)), \
|
||||
INIT_SET(M_C3(dict_, type, _init_set)), \
|
||||
SET(M_C3(dict_, type, _set)), \
|
||||
CLEAR(M_C3(dict_, type, _clear)), \
|
||||
INIT_MOVE(M_C3(dict_, type, _init_move)), \
|
||||
MOVE(M_C3(dict_, type, _move)), \
|
||||
TYPE(M_C3(dict_, type, _t)), \
|
||||
SUBTYPE(M_C3(dict_pair_,type,_t)), \
|
||||
IT_TYPE(M_C3(dict_it_,type,_t)), \
|
||||
IT_FIRST(M_C3(dict_,type,_it)), \
|
||||
IT_SET(M_C3(dict_, type, _it_set)), \
|
||||
IT_END_P(M_C3(dict_,type,_end_p)), \
|
||||
IT_LAST_P(M_C3(dict_,type,_last_p)), \
|
||||
IT_NEXT(M_C3(dict_,type,_next)), \
|
||||
IT_REF(M_C3(dict_,type,_ref)), \
|
||||
IT_CREF(M_C3(dict_,type,_cref)) \
|
||||
,M_IF_METHOD_BOTH(GET_STR, key_oplist, value_oplist)(GET_STR(M_C3(array_, type, _get_str)),) \
|
||||
,M_IF_METHOD_BOTH(OUT_STR, key_oplist, value_oplist)(OUT_STR(M_C3(array_, type, _out_str)),) \
|
||||
,M_IF_METHOD_BOTH(IN_STR, key_oplist, value_oplist)(IN_STR(M_C3(array_, type, _in_str)),) \
|
||||
,M_IF_METHOD(EQUAL, value_oplist)(EQUAL(M_C3(dict_, type, _equal_p)),) \
|
||||
,KEY_OPLIST(key_oplist) \
|
||||
,VALUE_OPLIST(value_oplist) \
|
||||
)
|
||||
@@ -462,7 +462,7 @@
|
||||
|
||||
#define DICTI_CONTRACT(name, map) do { \
|
||||
assert(map->used <= map->upper_limit); \
|
||||
assert(M_POWEROF2_P(CAT3(array_list_dict_pair_,name,_size)(map->table))); \
|
||||
assert(M_POWEROF2_P(M_C3(array_list_dict_pair_,name,_size)(map->table))); \
|
||||
} while (0)
|
||||
|
||||
#endif
|
||||
+79
-79
@@ -38,9 +38,9 @@
|
||||
type: name of the type of the structure (aka. struct test_s) - not used currently
|
||||
*/
|
||||
#define ILIST_INTERFACE(name, type) \
|
||||
struct CAT3(ilist_head_, name, _s) { \
|
||||
struct CAT3(ilist_head_, name, _s) *next; \
|
||||
struct CAT3(ilist_head_, name, _s) *prev; \
|
||||
struct M_C3(ilist_head_, name, _s) { \
|
||||
struct M_C3(ilist_head_, name, _s) *next; \
|
||||
struct M_C3(ilist_head_, name, _s) *prev; \
|
||||
} name
|
||||
|
||||
/* Define a list of a given type.
|
||||
@@ -52,21 +52,21 @@
|
||||
|
||||
/* Define the oplist of an ilist of type */
|
||||
#define ILIST_OPLIST(name) \
|
||||
(INIT(CAT3(ilist_, name, _init)), \
|
||||
CLEAR(CAT3(ilist_, name, _clear)), \
|
||||
TYPE(CAT3(ilist_,name,_t)), \
|
||||
SUBTYPE(CAT3(ilist_type_,name,_t)), \
|
||||
IT_TYPE(CAT3(ilist_it_,name,_t)), \
|
||||
IT_FIRST(CAT3(ilist_,name,_it)), \
|
||||
IT_SET(CAT3(ilist_,name,_it_set)), \
|
||||
IT_END_P(CAT3(ilist_,name,_end_p)), \
|
||||
IT_LAST_P(CAT3(ilist_,name,_last_p)), \
|
||||
IT_EQUAL_P(CAT3(ilist_,name,_it_equal_p)), \
|
||||
IT_NEXT(CAT3(ilist_,name,_next)), \
|
||||
IT_REF(CAT3(ilist_,name,_ref)), \
|
||||
IT_CREF(CAT3(ilist_,name,_cref)), \
|
||||
PUSH(CAT3(ilist_,name,_push_back)), \
|
||||
POP(CAT3(ilist_,name,_pop_back)) \
|
||||
(INIT(M_C3(ilist_, name, _init)), \
|
||||
CLEAR(M_C3(ilist_, name, _clear)), \
|
||||
TYPE(M_C3(ilist_,name,_t)), \
|
||||
SUBTYPE(M_C3(ilist_type_,name,_t)), \
|
||||
IT_TYPE(M_C3(ilist_it_,name,_t)), \
|
||||
IT_FIRST(M_C3(ilist_,name,_it)), \
|
||||
IT_SET(M_C3(ilist_,name,_it_set)), \
|
||||
IT_END_P(M_C3(ilist_,name,_end_p)), \
|
||||
IT_LAST_P(M_C3(ilist_,name,_last_p)), \
|
||||
IT_EQUAL_P(M_C3(ilist_,name,_it_equal_p)), \
|
||||
IT_NEXT(M_C3(ilist_,name,_next)), \
|
||||
IT_REF(M_C3(ilist_,name,_ref)), \
|
||||
IT_CREF(M_C3(ilist_,name,_cref)), \
|
||||
PUSH(M_C3(ilist_,name,_push_back)), \
|
||||
POP(M_C3(ilist_,name,_pop_back)) \
|
||||
)
|
||||
//TODO: Add oplist as optional argument of ILIST_OPLIST
|
||||
|
||||
@@ -90,114 +90,114 @@
|
||||
((type *)(void*)( (char *)(ptr) - offsetof(type, field) )) )
|
||||
|
||||
#define ILISTI_DEF2(name, type, oplist, check_instance) \
|
||||
typedef struct CAT3(ilist_head_, name, _s) CAT3(ilist_, name, _t)[1]; \
|
||||
typedef struct M_C3(ilist_head_, name, _s) M_C3(ilist_, name, _t)[1]; \
|
||||
\
|
||||
typedef type CAT3(ilist_type_,name, _t); \
|
||||
typedef type M_C3(ilist_type_,name, _t); \
|
||||
\
|
||||
typedef struct CAT3(ilist_it_, name, _s) { \
|
||||
struct CAT3(ilist_head_, name, _s) *head; \
|
||||
struct CAT3(ilist_head_, name, _s) *previous; \
|
||||
struct CAT3(ilist_head_, name, _s) *current; \
|
||||
struct CAT3(ilist_head_, name, _s) *next; \
|
||||
} CAT3(ilist_it_, name, _t)[1]; \
|
||||
typedef struct M_C3(ilist_it_, name, _s) { \
|
||||
struct M_C3(ilist_head_, name, _s) *head; \
|
||||
struct M_C3(ilist_head_, name, _s) *previous; \
|
||||
struct M_C3(ilist_head_, name, _s) *current; \
|
||||
struct M_C3(ilist_head_, name, _s) *next; \
|
||||
} M_C3(ilist_it_, name, _t)[1]; \
|
||||
\
|
||||
typedef union { \
|
||||
type *ptr; \
|
||||
const type *cptr; \
|
||||
} CAT3(ilist_union_, name,_t); \
|
||||
} M_C3(ilist_union_, name,_t); \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(ilist_, name, _const_cast)(type *ptr) \
|
||||
M_C3(ilist_, name, _const_cast)(type *ptr) \
|
||||
{ \
|
||||
CAT3(ilist_union_, name,_t) u; \
|
||||
M_C3(ilist_union_, name,_t) u; \
|
||||
u.ptr = ptr; \
|
||||
return u.cptr; \
|
||||
} \
|
||||
\
|
||||
M_IF(check_instance)(bool CAT3(ilist_instance_, name, _g);, ) \
|
||||
M_IF(check_instance)(bool M_C3(ilist_instance_, name, _g);, ) \
|
||||
\
|
||||
static inline void CAT3(ilist_, name, _init)(CAT3(ilist_, name, _t) list) \
|
||||
static inline void M_C3(ilist_, name, _init)(M_C3(ilist_, name, _t) list) \
|
||||
{ \
|
||||
assert (list != NULL); \
|
||||
M_IF(check_instance)(assert (CAT3(ilist_instance_, name, _g) == false),); \
|
||||
M_IF(check_instance)(CAT3(ilist_instance_, name, _g) = true,); \
|
||||
M_IF(check_instance)(assert (M_C3(ilist_instance_, name, _g) == false),); \
|
||||
M_IF(check_instance)(M_C3(ilist_instance_, name, _g) = true,); \
|
||||
list->next = list; \
|
||||
list->prev = list; \
|
||||
} \
|
||||
\
|
||||
static inline void CAT3(ilist_, name, _clean)(CAT3(ilist_, name, _t) list) \
|
||||
static inline void M_C3(ilist_, name, _clean)(M_C3(ilist_, name, _t) list) \
|
||||
{ \
|
||||
assert (list != NULL); \
|
||||
list->next = list; \
|
||||
list->prev = list; \
|
||||
} \
|
||||
\
|
||||
static inline void CAT3(ilist_, name, _clear)(CAT3(ilist_, name, _t) list) \
|
||||
static inline void M_C3(ilist_, name, _clear)(M_C3(ilist_, name, _t) list) \
|
||||
{ \
|
||||
M_IF(check_instance)(assert (CAT3(ilist_instance_, name, _g) == true),); \
|
||||
M_IF(check_instance)(CAT3(ilist_instance_, name, _g) = false,); \
|
||||
CAT3(ilist_, name, _clean)(list); \
|
||||
M_IF(check_instance)(assert (M_C3(ilist_instance_, name, _g) == true),); \
|
||||
M_IF(check_instance)(M_C3(ilist_instance_, name, _g) = false,); \
|
||||
M_C3(ilist_, name, _clean)(list); \
|
||||
} \
|
||||
\
|
||||
static inline bool CAT3(ilist_, name, _empty_p)(const CAT3(ilist_, name, _t) list) \
|
||||
static inline bool M_C3(ilist_, name, _empty_p)(const M_C3(ilist_, name, _t) list) \
|
||||
{ \
|
||||
return list->next == list; \
|
||||
} \
|
||||
\
|
||||
static inline size_t CAT3(ilist_, name, _size)(const CAT3(ilist_, name, _t) list) \
|
||||
static inline size_t M_C3(ilist_, name, _size)(const M_C3(ilist_, name, _t) list) \
|
||||
{ \
|
||||
size_t s = 0; \
|
||||
for(const struct CAT3(ilist_head_, name, _s) *it = list->next ; \
|
||||
for(const struct M_C3(ilist_head_, name, _s) *it = list->next ; \
|
||||
it != list; it = it->next) \
|
||||
s++; \
|
||||
return s; \
|
||||
} \
|
||||
\
|
||||
static inline void CAT3(ilist_, name, _push_back)(CAT3(ilist_, name, _t) list, \
|
||||
static inline void M_C3(ilist_, name, _push_back)(M_C3(ilist_, name, _t) list, \
|
||||
type *obj) \
|
||||
{ \
|
||||
assert (list != NULL && obj != NULL); \
|
||||
struct CAT3(ilist_head_, name, _s) *prev = list->prev; \
|
||||
struct M_C3(ilist_head_, name, _s) *prev = list->prev; \
|
||||
list->prev = &obj->name; \
|
||||
obj->name.prev = prev; \
|
||||
obj->name.next = list; \
|
||||
prev->next = &obj->name; \
|
||||
} \
|
||||
\
|
||||
static inline void CAT3(ilist_, name, _push_front)(CAT3(ilist_, name, _t) list, \
|
||||
static inline void M_C3(ilist_, name, _push_front)(M_C3(ilist_, name, _t) list, \
|
||||
type *obj) \
|
||||
{ \
|
||||
assert (list != NULL && obj != NULL); \
|
||||
struct CAT3(ilist_head_, name, _s) *next = list->next; \
|
||||
struct M_C3(ilist_head_, name, _s) *next = list->next; \
|
||||
list->next = &obj->name; \
|
||||
obj->name.next = next; \
|
||||
obj->name.prev = list; \
|
||||
next->prev = &obj->name; \
|
||||
} \
|
||||
\
|
||||
static inline void CAT3(ilist_, name, _push_after)(type *obj_it, \
|
||||
static inline void M_C3(ilist_, name, _push_after)(type *obj_it, \
|
||||
type *obj_ins) \
|
||||
{ \
|
||||
assert (obj_it != NULL && obj_ins != NULL); \
|
||||
struct CAT3(ilist_head_, name, _s) *next = obj_it->name.next; \
|
||||
struct M_C3(ilist_head_, name, _s) *next = obj_it->name.next; \
|
||||
obj_it->name.next = &obj_ins->name; \
|
||||
obj_ins->name.next = next; \
|
||||
obj_ins->name.prev = &obj_it->name; \
|
||||
next->prev = &obj_ins->name; \
|
||||
} \
|
||||
\
|
||||
static inline void CAT3(ilist_, name, _init_field)(type *obj) \
|
||||
static inline void M_C3(ilist_, name, _init_field)(type *obj) \
|
||||
{ \
|
||||
assert (obj != NULL); \
|
||||
obj->name.next = NULL; \
|
||||
obj->name.prev = NULL; \
|
||||
} \
|
||||
\
|
||||
static inline void CAT3(ilist_, name, _unlink)(type *obj) \
|
||||
static inline void M_C3(ilist_, name, _unlink)(type *obj) \
|
||||
{ \
|
||||
assert (obj != NULL); \
|
||||
struct CAT3(ilist_head_, name, _s) *next = obj->name.next; \
|
||||
struct CAT3(ilist_head_, name, _s) *prev = obj->name.prev; \
|
||||
struct M_C3(ilist_head_, name, _s) *next = obj->name.next; \
|
||||
struct M_C3(ilist_head_, name, _s) *prev = obj->name.prev; \
|
||||
next->prev = prev; \
|
||||
prev->next = next; \
|
||||
obj->name.next = NULL; \
|
||||
@@ -205,24 +205,24 @@
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(ilist_, name, _back)(const CAT3(ilist_, name,_t) list) \
|
||||
M_C3(ilist_, name, _back)(const M_C3(ilist_, name,_t) list) \
|
||||
{ \
|
||||
assert(list != NULL && !CAT3(ilist_, name, _empty_p)(list)); \
|
||||
assert(list != NULL && !M_C3(ilist_, name, _empty_p)(list)); \
|
||||
return ILISTI_TYPE_FROM_FIELD(type, list->prev, \
|
||||
struct CAT3(ilist_head_, name, _s), name); \
|
||||
struct M_C3(ilist_head_, name, _s), name); \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(ilist_, name, _front)(const CAT3(ilist_, name,_t) list) \
|
||||
M_C3(ilist_, name, _front)(const M_C3(ilist_, name,_t) list) \
|
||||
{ \
|
||||
assert(list != NULL && !CAT3(ilist_, name, _empty_p)(list)); \
|
||||
assert(list != NULL && !M_C3(ilist_, name, _empty_p)(list)); \
|
||||
return ILISTI_TYPE_FROM_FIELD(type, list->next, \
|
||||
struct CAT3(ilist_head_, name, _s), name); \
|
||||
struct M_C3(ilist_head_, name, _s), name); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(ilist_, name, _it)(CAT3(ilist_it_, name,_t) it, \
|
||||
CAT3(ilist_, name,_t) list) \
|
||||
M_C3(ilist_, name, _it)(M_C3(ilist_it_, name,_t) it, \
|
||||
M_C3(ilist_, name,_t) list) \
|
||||
{ \
|
||||
assert (it != NULL && list != NULL); \
|
||||
assert (list->next != NULL && list->next->next != NULL); \
|
||||
@@ -233,8 +233,8 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(ilist_, name, _it_set)(CAT3(ilist_it_, name,_t) it, \
|
||||
const CAT3(ilist_it_, name,_t) cit) \
|
||||
M_C3(ilist_, name, _it_set)(M_C3(ilist_it_, name,_t) it, \
|
||||
const M_C3(ilist_it_, name,_t) cit) \
|
||||
{ \
|
||||
assert (it != NULL && cit != NULL); \
|
||||
it->head = cit->head; \
|
||||
@@ -244,21 +244,21 @@
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(ilist_, name, _end_p)(const CAT3(ilist_it_, name,_t) it) \
|
||||
M_C3(ilist_, name, _end_p)(const M_C3(ilist_it_, name,_t) it) \
|
||||
{ \
|
||||
assert (it != NULL); \
|
||||
return it->current == it->head; \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(ilist_, name, _last_p)(const CAT3(ilist_it_, name,_t) it) \
|
||||
M_C3(ilist_, name, _last_p)(const M_C3(ilist_it_, name,_t) it) \
|
||||
{ \
|
||||
assert (it != NULL); \
|
||||
return it->next == it->head; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(ilist_, name, _next)(CAT3(ilist_it_, name,_t) it) \
|
||||
M_C3(ilist_, name, _next)(M_C3(ilist_it_, name,_t) it) \
|
||||
{ \
|
||||
assert (it != NULL); \
|
||||
/* Can't set it->previous to it->current. \
|
||||
@@ -271,7 +271,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(ilist_, name, _previous)(CAT3(ilist_it_, name,_t) it) \
|
||||
M_C3(ilist_, name, _previous)(M_C3(ilist_it_, name,_t) it) \
|
||||
{ \
|
||||
assert (it != NULL); \
|
||||
/* Can't set it->next to it->current. \
|
||||
@@ -284,8 +284,8 @@
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(ilist_, name, _it_equal_p)(const CAT3(ilist_it_, name,_t) it1, \
|
||||
const CAT3(ilist_it_, name,_t) it2 ) \
|
||||
M_C3(ilist_, name, _it_equal_p)(const M_C3(ilist_it_, name,_t) it1, \
|
||||
const M_C3(ilist_it_, name,_t) it2 ) \
|
||||
{ \
|
||||
assert (it1 != NULL && it2 != NULL); \
|
||||
/* No need to check for next & previous */ \
|
||||
@@ -293,39 +293,39 @@
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(ilist_, name, _ref)(const CAT3(ilist_it_, name,_t) it) \
|
||||
M_C3(ilist_, name, _ref)(const M_C3(ilist_it_, name,_t) it) \
|
||||
{ \
|
||||
assert (it != NULL && it->current != NULL); \
|
||||
/* check if 'it' was not deleted */ \
|
||||
assert (it->current->next == it->next); \
|
||||
assert (it->current->prev == it->previous); \
|
||||
assert (!CAT3(ilist_, name, _end_p)(it)); \
|
||||
assert (!M_C3(ilist_, name, _end_p)(it)); \
|
||||
return ILISTI_TYPE_FROM_FIELD(type, it->current, \
|
||||
struct CAT3(ilist_head_, name, _s), name); \
|
||||
struct M_C3(ilist_head_, name, _s), name); \
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(ilist_, name, _cref)(const CAT3(ilist_it_, name,_t) it) \
|
||||
M_C3(ilist_, name, _cref)(const M_C3(ilist_it_, name,_t) it) \
|
||||
{ \
|
||||
type *ptr = CAT3(ilist_, name, _ref)(it); \
|
||||
return CAT3(ilist_, name, _const_cast)(ptr); \
|
||||
type *ptr = M_C3(ilist_, name, _ref)(it); \
|
||||
return M_C3(ilist_, name, _const_cast)(ptr); \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(ilist_, name, _pop_back)(CAT3(ilist_, name,_t) list) \
|
||||
M_C3(ilist_, name, _pop_back)(M_C3(ilist_, name,_t) list) \
|
||||
{ \
|
||||
assert (!CAT3(ilist_, name, _empty_p)(list)); \
|
||||
type *obj = CAT3(ilist_, name, _back)(list); \
|
||||
assert (!M_C3(ilist_, name, _empty_p)(list)); \
|
||||
type *obj = M_C3(ilist_, name, _back)(list); \
|
||||
list->prev = list->prev->prev; \
|
||||
list->prev->next = list; \
|
||||
return obj; \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(ilist_, name, _pop_front)(CAT3(ilist_, name,_t) list) \
|
||||
M_C3(ilist_, name, _pop_front)(M_C3(ilist_, name,_t) list) \
|
||||
{ \
|
||||
assert (!CAT3(ilist_, name, _empty_p)(list)); \
|
||||
type *obj = CAT3(ilist_, name, _front)(list); \
|
||||
assert (!M_C3(ilist_, name, _empty_p)(list)); \
|
||||
type *obj = M_C3(ilist_, name, _front)(list); \
|
||||
list->next = list->next->next; \
|
||||
list->next->prev = list; \
|
||||
return obj; \
|
||||
|
||||
+21
-21
@@ -34,18 +34,18 @@
|
||||
|
||||
#define ISHARED_PTR_OPLIST(name) ( \
|
||||
INIT(M_INIT_DEFAULT), \
|
||||
CLEAR(CAT3(ishared_, name, _clear)), \
|
||||
SET(CAT3(ishared_, name, _set) M_IPTR), \
|
||||
INIT_SET(CAT3(ishared_, name, _init_set2) M_IPTR), \
|
||||
TYPE(CAT3(ishared_,name,_t)), \
|
||||
SUBTYPE(CAT3(ishared_type_,name,_t)), \
|
||||
CLEAR(M_C3(ishared_, name, _clear)), \
|
||||
SET(M_C3(ishared_, name, _set) M_IPTR), \
|
||||
INIT_SET(M_C3(ishared_, name, _init_set2) M_IPTR), \
|
||||
TYPE(M_C3(ishared_,name,_t)), \
|
||||
SUBTYPE(M_C3(ishared_type_,name,_t)), \
|
||||
)
|
||||
|
||||
/* Interface to add to a structure to allow intrusive support.
|
||||
name: name of the intrusive shared pointer.
|
||||
type: name of the type of the structure (aka. struct test_s) - not used currently */
|
||||
#define ISHARED_PTR_INTERFACE(name, type) \
|
||||
int CAT(name, _cpt)
|
||||
int M_C(name, _cpt)
|
||||
|
||||
|
||||
#define ISHARED_PTR_DEF(name, ...) \
|
||||
@@ -57,37 +57,37 @@
|
||||
|
||||
#define ISHAREDI_PTR_DEF2(name, type, oplist) \
|
||||
\
|
||||
typedef type *CAT3(ishared_,name,_t); \
|
||||
typedef type CAT3(ishared_type_,name,_t); \
|
||||
typedef type *M_C3(ishared_,name,_t); \
|
||||
typedef type M_C3(ishared_type_,name,_t); \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(ishared_, name, _init)(type *ptr) \
|
||||
M_C3(ishared_, name, _init)(type *ptr) \
|
||||
{ \
|
||||
if (ptr != NULL) \
|
||||
ptr->CAT(name, _cpt) = 1; \
|
||||
ptr->M_C(name, _cpt) = 1; \
|
||||
return ptr; \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(ishared_, name, _init_set)(type *shared) \
|
||||
M_C3(ishared_, name, _init_set)(type *shared) \
|
||||
{ \
|
||||
if (shared != NULL) \
|
||||
atomic_fetch_add(&(shared->CAT(name, _cpt)), 1); \
|
||||
atomic_fetch_add(&(shared->M_C(name, _cpt)), 1); \
|
||||
return shared; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(ishared_, name, _init_set2)(type ** ptr, type *shared) \
|
||||
M_C3(ishared_, name, _init_set2)(type ** ptr, type *shared) \
|
||||
{ \
|
||||
assert (ptr != NULL); \
|
||||
*ptr = CAT3(ishared_, name, _init_set)(shared); \
|
||||
*ptr = M_C3(ishared_, name, _init_set)(shared); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(ishared_, name, _clear)(type *shared) \
|
||||
M_C3(ishared_, name, _clear)(type *shared) \
|
||||
{ \
|
||||
if (shared != NULL) { \
|
||||
if (atomic_fetch_sub(&(shared->CAT(name, _cpt)), 1) == 1) { \
|
||||
if (atomic_fetch_sub(&(shared->M_C(name, _cpt)), 1) == 1) { \
|
||||
M_GET_CLEAR oplist (*shared); \
|
||||
M_GET_DEL oplist (shared); \
|
||||
} \
|
||||
@@ -95,17 +95,17 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(ishared_, name, _release)(type *shared) \
|
||||
M_C3(ishared_, name, _release)(type *shared) \
|
||||
{ \
|
||||
CAT3(ishared_, name, _clear)(shared); \
|
||||
M_C3(ishared_, name, _clear)(shared); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(ishared_, name, _set)(type ** ptr, type *shared) \
|
||||
M_C3(ishared_, name, _set)(type ** ptr, type *shared) \
|
||||
{ \
|
||||
assert (ptr != NULL); \
|
||||
CAT3(ishared_, name, _clear)(*ptr); \
|
||||
*ptr = CAT3(ishared_, name, _init_set)(shared); \
|
||||
M_C3(ishared_, name, _clear)(*ptr); \
|
||||
*ptr = M_C3(ishared_, name, _init_set)(shared); \
|
||||
} \
|
||||
\
|
||||
|
||||
|
||||
@@ -50,78 +50,78 @@
|
||||
/********************************** INTERNAL ************************************/
|
||||
|
||||
#define LISTI_OPLIST(name, oplist) \
|
||||
(INIT(CAT3(list_, name, _init)), \
|
||||
INIT_SET(CAT3(list_, name, _init_set)), \
|
||||
SET(CAT3(list_, name, _set)), \
|
||||
CLEAR(CAT3(list_, name, _clear)), \
|
||||
MOVE(CAT3(list_, name, _move)), \
|
||||
INIT_MOVE(CAT3(list_, name, _init_move)), \
|
||||
TYPE(CAT3(list_,name,_t)), \
|
||||
SUBTYPE(CAT3(list_type_,name,_t)), \
|
||||
IT_TYPE(CAT3(list_it_,name,_t)), \
|
||||
IT_FIRST(CAT3(list_,name,_it)), \
|
||||
IT_SET(CAT3(list_,name,_it_set)), \
|
||||
IT_END_P(CAT3(list_,name,_end_p)), \
|
||||
IT_EQUAL_P(CAT3(list_,name,_it_equal_p)), \
|
||||
IT_LAST_P(CAT3(list_,name,_last_p)), \
|
||||
IT_NEXT(CAT3(list_,name,_next)), \
|
||||
IT_REF(CAT3(list_,name,_ref)), \
|
||||
IT_CREF(CAT3(list_,name,_cref)), \
|
||||
CLEAN(CAT3(list_,name,_clean)), \
|
||||
PUSH(CAT3(list_,name,_push_back)), \
|
||||
POP(CAT3(list_,name,_pop_back)) \
|
||||
,REVERSE(CAT3(list_,name,_reverse)) \
|
||||
(INIT(M_C3(list_, name, _init)), \
|
||||
INIT_SET(M_C3(list_, name, _init_set)), \
|
||||
SET(M_C3(list_, name, _set)), \
|
||||
CLEAR(M_C3(list_, name, _clear)), \
|
||||
MOVE(M_C3(list_, name, _move)), \
|
||||
INIT_MOVE(M_C3(list_, name, _init_move)), \
|
||||
TYPE(M_C3(list_,name,_t)), \
|
||||
SUBTYPE(M_C3(list_type_,name,_t)), \
|
||||
IT_TYPE(M_C3(list_it_,name,_t)), \
|
||||
IT_FIRST(M_C3(list_,name,_it)), \
|
||||
IT_SET(M_C3(list_,name,_it_set)), \
|
||||
IT_END_P(M_C3(list_,name,_end_p)), \
|
||||
IT_EQUAL_P(M_C3(list_,name,_it_equal_p)), \
|
||||
IT_LAST_P(M_C3(list_,name,_last_p)), \
|
||||
IT_NEXT(M_C3(list_,name,_next)), \
|
||||
IT_REF(M_C3(list_,name,_ref)), \
|
||||
IT_CREF(M_C3(list_,name,_cref)), \
|
||||
CLEAN(M_C3(list_,name,_clean)), \
|
||||
PUSH(M_C3(list_,name,_push_back)), \
|
||||
POP(M_C3(list_,name,_pop_back)) \
|
||||
,REVERSE(M_C3(list_,name,_reverse)) \
|
||||
,OPLIST(oplist) \
|
||||
,M_IF_METHOD(GET_STR, oplist)(GET_STR(CAT3(list_, name, _get_str)),) \
|
||||
,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(CAT3(list_, name, _out_str)),) \
|
||||
,M_IF_METHOD(IN_STR, oplist)(IN_STR(CAT3(list_, name, _in_str)),) \
|
||||
,M_IF_METHOD(EQUAL, oplist)(EQUAL(CAT3(list_, name, _equal_p)),) \
|
||||
,M_IF_METHOD(GET_STR, oplist)(GET_STR(M_C3(list_, name, _get_str)),) \
|
||||
,M_IF_METHOD(OUT_STR, oplist)(OUT_STR(M_C3(list_, name, _out_str)),) \
|
||||
,M_IF_METHOD(IN_STR, oplist)(IN_STR(M_C3(list_, name, _in_str)),) \
|
||||
,M_IF_METHOD(EQUAL, oplist)(EQUAL(M_C3(list_, name, _equal_p)),) \
|
||||
)
|
||||
|
||||
#define LISTI_DEF2(name, type, oplist) \
|
||||
typedef struct CAT3(list_, name, _s) { \
|
||||
struct CAT3(list_, name, _s) *next; \
|
||||
typedef struct M_C3(list_, name, _s) { \
|
||||
struct M_C3(list_, name, _s) *next; \
|
||||
type data; \
|
||||
} *CAT3(list_, name,_t)[1]; \
|
||||
} *M_C3(list_, name,_t)[1]; \
|
||||
\
|
||||
typedef struct CAT3(list_, name, _s) **CAT3(list_,name, _ptr); \
|
||||
typedef struct M_C3(list_, name, _s) **M_C3(list_,name, _ptr); \
|
||||
\
|
||||
typedef const struct CAT3(list_, name, _s) *const*CAT3(list_,name, _srcptr);\
|
||||
typedef const struct M_C3(list_, name, _s) *const*M_C3(list_,name, _srcptr);\
|
||||
\
|
||||
typedef type CAT3(list_type_,name, _t); \
|
||||
typedef type M_C3(list_type_,name, _t); \
|
||||
\
|
||||
typedef struct CAT3(list_it_, name, _s) { \
|
||||
struct CAT3(list_, name, _s) *previous; \
|
||||
CAT3(list_, name,_t) l; \
|
||||
} CAT3(list_it_, name,_t)[1]; \
|
||||
typedef struct M_C3(list_it_, name, _s) { \
|
||||
struct M_C3(list_, name, _s) *previous; \
|
||||
M_C3(list_, name,_t) l; \
|
||||
} M_C3(list_it_, name,_t)[1]; \
|
||||
\
|
||||
typedef union { \
|
||||
type *ptr; \
|
||||
const type *cptr; \
|
||||
} CAT3(list_union_, name,_t); \
|
||||
} M_C3(list_union_, name,_t); \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(list_, name, _const_cast)(type *ptr) \
|
||||
M_C3(list_, name, _const_cast)(type *ptr) \
|
||||
{ \
|
||||
CAT3(list_union_, name,_t) u; \
|
||||
M_C3(list_union_, name,_t) u; \
|
||||
u.ptr = ptr; \
|
||||
return u.cptr; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _init)(CAT3(list_, name,_t) v) \
|
||||
M_C3(list_, name, _init)(M_C3(list_, name,_t) v) \
|
||||
{ \
|
||||
assert( v != NULL); \
|
||||
*v = NULL; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _clean)(CAT3(list_, name,_t) v) \
|
||||
M_C3(list_, name, _clean)(M_C3(list_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
struct CAT3(list_, name, _s) *it = *v; \
|
||||
struct M_C3(list_, name, _s) *it = *v; \
|
||||
while (it != NULL) { \
|
||||
struct CAT3(list_, name, _s) *next = it->next; \
|
||||
struct M_C3(list_, name, _s) *next = it->next; \
|
||||
M_GET_CLEAR oplist(it->data); \
|
||||
M_MEMORY_FREE (it); \
|
||||
it = next; \
|
||||
@@ -130,26 +130,26 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _clear)(CAT3(list_, name,_t) v) \
|
||||
M_C3(list_, name, _clear)(M_C3(list_, name,_t) v) \
|
||||
{ \
|
||||
CAT3(list_, name, _clean)(v); \
|
||||
M_C3(list_, name, _clean)(v); \
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(list_, name, _back)(const CAT3(list_, name,_t) v) \
|
||||
M_C3(list_, name, _back)(const M_C3(list_, name,_t) v) \
|
||||
{ \
|
||||
assert(v != NULL && *v != NULL); \
|
||||
return CAT3(list_, name, _const_cast)(&((*v)->data)); \
|
||||
return M_C3(list_, name, _const_cast)(&((*v)->data)); \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(list_, name, _push_raw)(CAT3(list_, name,_t) v) \
|
||||
M_C3(list_, name, _push_raw)(M_C3(list_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL); \
|
||||
struct CAT3(list_, name, _s) *next; \
|
||||
next = M_MEMORY_ALLOC (struct CAT3(list_, name, _s)); \
|
||||
struct M_C3(list_, name, _s) *next; \
|
||||
next = M_MEMORY_ALLOC (struct M_C3(list_, name, _s)); \
|
||||
if (next == NULL) { \
|
||||
M_MEMORY_FULL(sizeof (struct CAT3(list_, name, _s))); \
|
||||
M_MEMORY_FULL(sizeof (struct M_C3(list_, name, _s))); \
|
||||
return NULL; \
|
||||
} \
|
||||
type *ret = &next->data; \
|
||||
@@ -159,18 +159,18 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _push_back)(CAT3(list_, name,_t) v, type const x) \
|
||||
M_C3(list_, name, _push_back)(M_C3(list_, name,_t) v, type const x) \
|
||||
{ \
|
||||
type *data = CAT3(list_, name, _push_raw)(v); \
|
||||
type *data = M_C3(list_, name, _push_raw)(v); \
|
||||
if (data == NULL) \
|
||||
return; \
|
||||
M_GET_INIT_SET oplist(*data, x); \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(list_, name, _push_new)(CAT3(list_, name,_t) v) \
|
||||
M_C3(list_, name, _push_new)(M_C3(list_, name,_t) v) \
|
||||
{ \
|
||||
type *data = CAT3(list_, name, _push_raw)(v); \
|
||||
type *data = M_C3(list_, name, _push_raw)(v); \
|
||||
if (data == NULL) \
|
||||
return NULL; \
|
||||
M_GET_INIT oplist(*data); \
|
||||
@@ -178,38 +178,38 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _pop_back)(type *data, CAT3(list_, name,_t) v) \
|
||||
M_C3(list_, name, _pop_back)(type *data, M_C3(list_, name,_t) v) \
|
||||
{ \
|
||||
assert(v != NULL && *v != NULL); \
|
||||
if (data != NULL) { \
|
||||
M_GET_SET oplist(*data, (*v)->data); \
|
||||
} \
|
||||
M_GET_CLEAR oplist((*v)->data); \
|
||||
struct CAT3(list_, name, _s) *tofree = *v; \
|
||||
struct M_C3(list_, name, _s) *tofree = *v; \
|
||||
*v = (*v)->next; \
|
||||
M_MEMORY_FREE (tofree); \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(list_, name, _empty_p)(const CAT3(list_, name,_t) v) \
|
||||
M_C3(list_, name, _empty_p)(const M_C3(list_, name,_t) v) \
|
||||
{ \
|
||||
assert (v!= NULL); \
|
||||
return *v == NULL; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _swap)(CAT3(list_, name,_t) l, \
|
||||
CAT3(list_, name,_t) v) \
|
||||
M_C3(list_, name, _swap)(M_C3(list_, name,_t) l, \
|
||||
M_C3(list_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL && l != NULL); \
|
||||
struct CAT3(list_, name, _s) *tmp = *l; \
|
||||
struct M_C3(list_, name, _s) *tmp = *l; \
|
||||
*l = *v; \
|
||||
*v = tmp; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _it)(CAT3(list_it_, name,_t) l, \
|
||||
const CAT3(list_, name,_t) v) \
|
||||
M_C3(list_, name, _it)(M_C3(list_it_, name,_t) l, \
|
||||
const M_C3(list_, name,_t) v) \
|
||||
{ \
|
||||
assert (v != NULL && l[0].l != NULL); \
|
||||
l[0].l[0] = *v; \
|
||||
@@ -217,8 +217,8 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _it_set)(CAT3(list_it_, name,_t) it1, \
|
||||
const CAT3(list_it_, name,_t) it2) \
|
||||
M_C3(list_, name, _it_set)(M_C3(list_it_, name,_t) it1, \
|
||||
const M_C3(list_it_, name,_t) it2) \
|
||||
{ \
|
||||
assert (it1 != NULL && it2 != NULL); \
|
||||
it1[0].l[0] = it2[0].l[0]; \
|
||||
@@ -226,21 +226,21 @@
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(list_, name, _end_p)(const CAT3(list_it_, name,_t) v) \
|
||||
M_C3(list_, name, _end_p)(const M_C3(list_it_, name,_t) v) \
|
||||
{ \
|
||||
assert (v!= NULL); \
|
||||
return v[0].l[0] == NULL; \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(list_, name, _last_p)(const CAT3(list_it_, name,_t) v) \
|
||||
M_C3(list_, name, _last_p)(const M_C3(list_it_, name,_t) v) \
|
||||
{ \
|
||||
assert (v!= NULL); \
|
||||
return v[0].l[0] == NULL || v[0].l[0]->next == NULL; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _next)(CAT3(list_it_, name,_t) tail) \
|
||||
M_C3(list_, name, _next)(M_C3(list_it_, name,_t) tail) \
|
||||
{ \
|
||||
assert(tail != NULL && tail[0].l[0] != NULL); \
|
||||
tail[0].previous = tail[0].l[0]; \
|
||||
@@ -248,34 +248,34 @@
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(list_, name, _it_equal_p)(const CAT3(list_it_, name,_t) it1, \
|
||||
const CAT3(list_it_, name,_t) it2) \
|
||||
M_C3(list_, name, _it_equal_p)(const M_C3(list_it_, name,_t) it1, \
|
||||
const M_C3(list_it_, name,_t) it2) \
|
||||
{ \
|
||||
assert(it1 != NULL && it2 != NULL); \
|
||||
return it1[0].l[0] == it2[0].l[0]; \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(list_, name, _ref)(CAT3(list_it_, name,_t) v) \
|
||||
M_C3(list_, name, _ref)(M_C3(list_it_, name,_t) v) \
|
||||
{ \
|
||||
assert(v != NULL && v[0].l[0] != NULL); \
|
||||
return &(v[0].l[0]->data); \
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(list_, name, _cref)(const CAT3(list_it_, name,_t) v) \
|
||||
M_C3(list_, name, _cref)(const M_C3(list_it_, name,_t) v) \
|
||||
{ \
|
||||
assert(v != NULL && v[0].l[0] != NULL); \
|
||||
return CAT3(list_, name, _const_cast)(&(v[0].l[0]->data)); \
|
||||
return M_C3(list_, name, _const_cast)(&(v[0].l[0]->data)); \
|
||||
} \
|
||||
\
|
||||
static inline size_t \
|
||||
CAT3(list_, name, _size)(const CAT3(list_, name,_t) list) \
|
||||
M_C3(list_, name, _size)(const M_C3(list_, name,_t) list) \
|
||||
{ \
|
||||
assert (list != NULL); \
|
||||
size_t size = 0; \
|
||||
/* FIXME: Store size field within the list to get faster? */ \
|
||||
struct CAT3(list_, name, _s) *it = *list; \
|
||||
struct M_C3(list_, name, _s) *it = *list; \
|
||||
while (it != NULL) { \
|
||||
size ++; \
|
||||
it = it->next; \
|
||||
@@ -284,11 +284,11 @@
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(list_, name, _sublist_p)(const CAT3(list_, name,_t) list, \
|
||||
const CAT3(list_it_, name,_t) sublist) \
|
||||
M_C3(list_, name, _sublist_p)(const M_C3(list_, name,_t) list, \
|
||||
const M_C3(list_it_, name,_t) sublist) \
|
||||
{ \
|
||||
assert (list != NULL && sublist != NULL); \
|
||||
struct CAT3(list_, name, _s) *it = *list; \
|
||||
struct M_C3(list_, name, _s) *it = *list; \
|
||||
while (it != NULL) { \
|
||||
if (it == sublist[0].l[0]) return true; \
|
||||
it = it->next; \
|
||||
@@ -297,12 +297,12 @@
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(list_, name, _get)(const CAT3(list_, name,_t) list, size_t i) \
|
||||
M_C3(list_, name, _get)(const M_C3(list_, name,_t) list, size_t i) \
|
||||
{ \
|
||||
assert (list != NULL); \
|
||||
struct CAT3(list_, name, _s) *it = *list; \
|
||||
struct M_C3(list_, name, _s) *it = *list; \
|
||||
/* FIXME: How to avoid the double iteration over the list? */ \
|
||||
size_t len = CAT3(list_,name,_size)(list); \
|
||||
size_t len = M_C3(list_,name,_size)(list); \
|
||||
assert (i < len); \
|
||||
size_t j = len-1; \
|
||||
while (it != NULL) { \
|
||||
@@ -315,22 +315,22 @@
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(list_, name, _cget)(const CAT3(list_, name,_t) l, size_t i) \
|
||||
M_C3(list_, name, _cget)(const M_C3(list_, name,_t) l, size_t i) \
|
||||
{ \
|
||||
return CAT3(list_, name, _const_cast)(CAT3(list_, name, _get)(l,i)); \
|
||||
return M_C3(list_, name, _const_cast)(M_C3(list_, name, _get)(l,i)); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _insert)(CAT3(list_, name,_t) list, \
|
||||
CAT3(list_it_, name,_t) insertion_point, \
|
||||
M_C3(list_, name, _insert)(M_C3(list_, name,_t) list, \
|
||||
M_C3(list_it_, name,_t) insertion_point, \
|
||||
type const x) \
|
||||
{ \
|
||||
assert (list != NULL && insertion_point != NULL); \
|
||||
assert(CAT3(list_, name, _sublist_p)(list, insertion_point)); \
|
||||
struct CAT3(list_, name, _s) *next; \
|
||||
next = M_MEMORY_ALLOC (struct CAT3(list_, name, _s)); \
|
||||
assert(M_C3(list_, name, _sublist_p)(list, insertion_point)); \
|
||||
struct M_C3(list_, name, _s) *next; \
|
||||
next = M_MEMORY_ALLOC (struct M_C3(list_, name, _s)); \
|
||||
if (next == NULL) { \
|
||||
M_MEMORY_FULL(sizeof (struct CAT3(list_, name, _s))); \
|
||||
M_MEMORY_FULL(sizeof (struct M_C3(list_, name, _s))); \
|
||||
return; \
|
||||
} \
|
||||
M_GET_INIT_SET oplist(next->data, x); \
|
||||
@@ -345,13 +345,13 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _remove)(CAT3(list_, name,_t) list, \
|
||||
CAT3(list_it_, name,_t) removing_point) \
|
||||
M_C3(list_, name, _remove)(M_C3(list_, name,_t) list, \
|
||||
M_C3(list_it_, name,_t) removing_point) \
|
||||
{ \
|
||||
assert (list != NULL && removing_point != NULL); \
|
||||
assert(removing_point[0].l[0] != NULL); \
|
||||
assert(CAT3(list_, name, _sublist_p)(list, removing_point)); \
|
||||
struct CAT3(list_, name, _s) *next = removing_point[0].l[0]->next; \
|
||||
assert(M_C3(list_, name, _sublist_p)(list, removing_point)); \
|
||||
struct M_C3(list_, name, _s) *next = removing_point[0].l[0]->next; \
|
||||
if (removing_point->previous == NULL) { \
|
||||
*list = next; \
|
||||
} else { \
|
||||
@@ -363,16 +363,16 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _move_back)(CAT3(list_, name,_t) nv, \
|
||||
CAT3(list_, name,_t) ov, \
|
||||
CAT3(list_it_, name,_t) it) \
|
||||
M_C3(list_, name, _move_back)(M_C3(list_, name,_t) nv, \
|
||||
M_C3(list_, name,_t) ov, \
|
||||
M_C3(list_it_, name,_t) it) \
|
||||
{ \
|
||||
assert (nv != NULL && ov != NULL && it != NULL && nv != ov); \
|
||||
assert(it[0].l[0] != NULL); \
|
||||
assert(CAT3(list_, name, _sublist_p)(ov, it)); \
|
||||
assert(M_C3(list_, name, _sublist_p)(ov, it)); \
|
||||
/* Remove it from ov */ \
|
||||
struct CAT3(list_, name, _s) *next = it[0].l[0]->next; \
|
||||
struct CAT3(list_, name, _s) *current = it[0].l[0]; \
|
||||
struct M_C3(list_, name, _s) *next = it[0].l[0]->next; \
|
||||
struct M_C3(list_, name, _s) *current = it[0].l[0]; \
|
||||
if (it->previous == NULL) { \
|
||||
*ov = next; \
|
||||
} else { \
|
||||
@@ -386,22 +386,22 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _set)(CAT3(list_, name,_t) list, \
|
||||
const CAT3(list_, name,_t) org) \
|
||||
M_C3(list_, name, _set)(M_C3(list_, name,_t) list, \
|
||||
const M_C3(list_, name,_t) org) \
|
||||
{ \
|
||||
assert (list != NULL && org != NULL); \
|
||||
struct CAT3(list_, name, _s) *next, *it_org; \
|
||||
struct CAT3(list_, name, _s) **update_list; \
|
||||
struct M_C3(list_, name, _s) *next, *it_org; \
|
||||
struct M_C3(list_, name, _s) **update_list; \
|
||||
if (list == org) return; \
|
||||
/* TODO: Reuse memory of list */ \
|
||||
CAT3(list_, name, _clean)(list); \
|
||||
M_C3(list_, name, _clean)(list); \
|
||||
update_list = list; \
|
||||
it_org = *org; \
|
||||
while (it_org != NULL) { \
|
||||
next = M_MEMORY_ALLOC (struct CAT3(list_, name, _s)); \
|
||||
next = M_MEMORY_ALLOC (struct M_C3(list_, name, _s)); \
|
||||
*update_list = next; \
|
||||
if (next == NULL) { \
|
||||
M_MEMORY_FULL(sizeof (struct CAT3(list_, name, _s))); \
|
||||
M_MEMORY_FULL(sizeof (struct M_C3(list_, name, _s))); \
|
||||
return; \
|
||||
} \
|
||||
update_list = &next->next; \
|
||||
@@ -412,17 +412,17 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _init_set)(CAT3(list_, name,_t) list, \
|
||||
const CAT3(list_, name,_t) org) \
|
||||
M_C3(list_, name, _init_set)(M_C3(list_, name,_t) list, \
|
||||
const M_C3(list_, name,_t) org) \
|
||||
{ \
|
||||
assert (list != NULL && org != NULL && list != org); \
|
||||
CAT3(list_, name, _init)(list); \
|
||||
CAT3(list_, name, _set)(list, org); \
|
||||
M_C3(list_, name, _init)(list); \
|
||||
M_C3(list_, name, _set)(list, org); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _init_move)(CAT3(list_, name,_t) list, \
|
||||
CAT3(list_, name,_t) org) \
|
||||
M_C3(list_, name, _init_move)(M_C3(list_, name,_t) list, \
|
||||
M_C3(list_, name,_t) org) \
|
||||
{ \
|
||||
assert (list != NULL && org != NULL && list != org); \
|
||||
*list = *org; \
|
||||
@@ -430,21 +430,21 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _move)(CAT3(list_, name,_t) list, \
|
||||
CAT3(list_, name,_t) org) \
|
||||
M_C3(list_, name, _move)(M_C3(list_, name,_t) list, \
|
||||
M_C3(list_, name,_t) org) \
|
||||
{ \
|
||||
assert (list != NULL && org != NULL && list != org); \
|
||||
CAT3(list_, name, _clear)(list); \
|
||||
CAT3(list_, name, _init_move)(list, org); \
|
||||
M_C3(list_, name, _clear)(list); \
|
||||
M_C3(list_, name, _init_move)(list, org); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _slice)(CAT3(list_, name,_t) list1, \
|
||||
CAT3(list_, name,_t) list2) \
|
||||
M_C3(list_, name, _slice)(M_C3(list_, name,_t) list1, \
|
||||
M_C3(list_, name,_t) list2) \
|
||||
{ \
|
||||
assert (list1 != NULL && list2 != NULL && list1 != list2); \
|
||||
struct CAT3(list_, name, _s) **update_list = list1; \
|
||||
struct CAT3(list_, name, _s) *it = *list1; \
|
||||
struct M_C3(list_, name, _s) **update_list = list1; \
|
||||
struct M_C3(list_, name, _s) *it = *list1; \
|
||||
while (it != NULL) { \
|
||||
update_list = &it->next; \
|
||||
it = it->next; \
|
||||
@@ -454,10 +454,10 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(list_, name, _reverse)(CAT3(list_, name,_t) list) \
|
||||
M_C3(list_, name, _reverse)(M_C3(list_, name,_t) list) \
|
||||
{ \
|
||||
assert (list != NULL); \
|
||||
struct CAT3(list_, name, _s) *previous = NULL, *it = *list, *next; \
|
||||
struct M_C3(list_, name, _s) *previous = NULL, *it = *list, *next; \
|
||||
while (it != NULL) { \
|
||||
next = it->next; \
|
||||
it->next = previous; \
|
||||
@@ -469,18 +469,18 @@
|
||||
\
|
||||
M_IF_METHOD(GET_STR, oplist)( \
|
||||
static inline void \
|
||||
CAT3(list_, name, _get_str)(string_t str, const CAT3(list_, name,_t) list, \
|
||||
M_C3(list_, name, _get_str)(string_t str, const M_C3(list_, name,_t) list, \
|
||||
bool append) \
|
||||
{ \
|
||||
assert (str != NULL && list != NULL); \
|
||||
(append ? string_cat_str : string_set_str) (str, "["); \
|
||||
CAT3(list_it_, name, _t) it; \
|
||||
for (CAT3(list_, name, _it)(it, list) ; \
|
||||
!CAT3(list_, name, _end_p)(it); \
|
||||
CAT3(list_, name, _next)(it)){ \
|
||||
const type *item = CAT3(list_, name, _cref)(it); \
|
||||
M_C3(list_it_, name, _t) it; \
|
||||
for (M_C3(list_, name, _it)(it, list) ; \
|
||||
!M_C3(list_, name, _end_p)(it); \
|
||||
M_C3(list_, name, _next)(it)){ \
|
||||
const type *item = M_C3(list_, name, _cref)(it); \
|
||||
M_GET_GET_STR oplist (str, *item, true); \
|
||||
if (!CAT3(list_, name, _last_p)(it)) \
|
||||
if (!M_C3(list_, name, _last_p)(it)) \
|
||||
string_push_back (str, M_GET_SEPARATOR oplist); \
|
||||
} \
|
||||
string_push_back (str, ']'); \
|
||||
@@ -489,17 +489,17 @@
|
||||
\
|
||||
M_IF_METHOD(OUT_STR, oplist)( \
|
||||
static inline void \
|
||||
CAT3(list_, name, _out_str)(FILE *file, const CAT3(list_, name,_t) list) \
|
||||
M_C3(list_, name, _out_str)(FILE *file, const M_C3(list_, name,_t) list) \
|
||||
{ \
|
||||
assert (file != NULL && list != NULL); \
|
||||
fputc ('[', file); \
|
||||
CAT3(list_it_, name, _t) it; \
|
||||
for (CAT3(list_, name, _it)(it, list) ; \
|
||||
!CAT3(list_, name, _end_p)(it); \
|
||||
CAT3(list_, name, _next)(it)){ \
|
||||
const type *item = CAT3(list_, name, _cref)(it); \
|
||||
M_C3(list_it_, name, _t) it; \
|
||||
for (M_C3(list_, name, _it)(it, list) ; \
|
||||
!M_C3(list_, name, _end_p)(it); \
|
||||
M_C3(list_, name, _next)(it)){ \
|
||||
const type *item = M_C3(list_, name, _cref)(it); \
|
||||
M_GET_OUT_STR oplist (file, *item); \
|
||||
if (!CAT3(list_, name, _last_p)(it)) \
|
||||
if (!M_C3(list_, name, _last_p)(it)) \
|
||||
fputc (M_GET_SEPARATOR oplist, file); \
|
||||
} \
|
||||
fputc (']', file); \
|
||||
@@ -508,10 +508,10 @@
|
||||
\
|
||||
M_IF_METHOD(IN_STR, oplist)( \
|
||||
static inline bool \
|
||||
CAT3(list_, name, _in_str)(CAT3(list_, name,_t) list, FILE *file) \
|
||||
M_C3(list_, name, _in_str)(M_C3(list_, name,_t) list, FILE *file) \
|
||||
{ \
|
||||
assert (file != NULL && list != NULL); \
|
||||
CAT3(list_, name,_clean)(list); \
|
||||
M_C3(list_, name,_clean)(list); \
|
||||
char c = fgetc(file); \
|
||||
if (c != '[') return false; \
|
||||
type item; \
|
||||
@@ -519,37 +519,37 @@
|
||||
do { \
|
||||
bool b = M_GET_IN_STR oplist (item, file); \
|
||||
if (!b) { c = 0; break; } \
|
||||
CAT3(list_, name, _push_back)(list, item); \
|
||||
M_C3(list_, name, _push_back)(list, item); \
|
||||
c = fgetc(file); \
|
||||
} while (c == M_GET_SEPARATOR oplist && !feof(file) && !ferror(file)); \
|
||||
M_GET_CLEAR oplist (item); \
|
||||
CAT3(list_, name, _reverse)(list); \
|
||||
M_C3(list_, name, _reverse)(list); \
|
||||
return c == ']'; \
|
||||
} \
|
||||
, /* no in_str */ ) \
|
||||
\
|
||||
M_IF_METHOD(EQUAL, oplist)( \
|
||||
static inline bool \
|
||||
CAT3(list_, name, _equal_p)(const CAT3(list_, name,_t) list1, \
|
||||
const CAT3(list_, name,_t) list2) \
|
||||
M_C3(list_, name, _equal_p)(const M_C3(list_, name,_t) list1, \
|
||||
const M_C3(list_, name,_t) list2) \
|
||||
{ \
|
||||
assert (list1 != NULL && list2 != NULL); \
|
||||
CAT3(list_it_, name, _t) it1; \
|
||||
CAT3(list_it_, name, _t) it2; \
|
||||
M_C3(list_it_, name, _t) it1; \
|
||||
M_C3(list_it_, name, _t) it2; \
|
||||
if (list1 == list2) return true; \
|
||||
CAT3(list_, name, _it)(it1, list1); \
|
||||
CAT3(list_, name, _it)(it2, list2); \
|
||||
while (!CAT3(list_, name, _end_p)(it1) \
|
||||
&&!CAT3(list_, name, _end_p)(it2)) { \
|
||||
const type *item1 = CAT3(list_, name, _cref)(it1); \
|
||||
const type *item2 = CAT3(list_, name, _cref)(it2); \
|
||||
M_C3(list_, name, _it)(it1, list1); \
|
||||
M_C3(list_, name, _it)(it2, list2); \
|
||||
while (!M_C3(list_, name, _end_p)(it1) \
|
||||
&&!M_C3(list_, name, _end_p)(it2)) { \
|
||||
const type *item1 = M_C3(list_, name, _cref)(it1); \
|
||||
const type *item2 = M_C3(list_, name, _cref)(it2); \
|
||||
bool b = M_GET_EQUAL oplist (*item1, *item2); \
|
||||
if (!b) return false; \
|
||||
CAT3(list_, name, _next)(it1); \
|
||||
CAT3(list_, name, _next)(it2); \
|
||||
M_C3(list_, name, _next)(it1); \
|
||||
M_C3(list_, name, _next)(it2); \
|
||||
} \
|
||||
return CAT3(list_, name, _end_p)(it1) \
|
||||
&& CAT3(list_, name, _end_p)(it2); \
|
||||
return M_C3(list_, name, _end_p)(it1) \
|
||||
&& M_C3(list_, name, _end_p)(it2); \
|
||||
} \
|
||||
, /* no equal */ ) \
|
||||
\
|
||||
|
||||
+100
-100
@@ -38,9 +38,9 @@
|
||||
#define RBTREE_DEF(name, ...) \
|
||||
M_IF_NARGS_EQ1(__VA_ARGS__) \
|
||||
(RBTREEI_DEF2(name, __VA_ARGS__, M_DEFAULT_OPLIST, \
|
||||
CAT3(rbtree_, name, _t), struct CAT3(rbtree_node_, name, _s)), \
|
||||
M_C3(rbtree_, name, _t), struct M_C3(rbtree_node_, name, _s)), \
|
||||
RBTREEI_DEF2(name, __VA_ARGS__ , \
|
||||
CAT3(rbtree_, name, _t), struct CAT3(rbtree_node_, name, _s)))
|
||||
M_C3(rbtree_, name, _t), struct M_C3(rbtree_node_, name, _s)))
|
||||
|
||||
/* Define the oplist of a rbtree of type.
|
||||
USAGE: RBTREE_OPLIST(name [, oplist_of_the_type]) */
|
||||
@@ -53,28 +53,28 @@
|
||||
/********************************** INTERNAL ************************************/
|
||||
|
||||
#define RBTREEI_OPLIST(name, oplist) \
|
||||
(INIT(CAT3(rbtree_, name, _init)), \
|
||||
INIT_SET(CAT3(rbtree_, name, _init_set)), \
|
||||
SET(CAT3(rbtree_, name, _set)), \
|
||||
CLEAR(CAT3(rbtree_, name, _clear)), \
|
||||
INIT_MOVE(CAT3(rbtree_, name, _init_move)), \
|
||||
MOVE(CAT3(rbtree_, name, _move)), \
|
||||
TYPE(CAT3(rbtree_,name,_t)), \
|
||||
SUBTYPE(CAT3(rbtree_type_,name,_t)), \
|
||||
IT_TYPE(CAT3(rbtree_it_,name,_t)), \
|
||||
IT_FIRST(CAT3(rbtree_,name,_it)), \
|
||||
IT_SET(CAT3(rbtree_,name,_it_set)), \
|
||||
IT_END_P(CAT3(rbtree_,name,_end_p)), \
|
||||
IT_LAST_P(CAT3(rbtree_,name,_last_p)), \
|
||||
IT_EQUAL_P(CAT3(rbtree_,name,_it_equal_p)), \
|
||||
IT_NEXT(CAT3(rbtree_,name,_next)), \
|
||||
IT_REF(CAT3(rbtree_,name,_ref)), \
|
||||
IT_CREF(CAT3(rbtree_,name,_cref)), \
|
||||
CLEAN(CAT3(rbtree_,name,_clean)), \
|
||||
PUSH(CAT3(rbtree_,name,_push)), \
|
||||
POP(CAT3(rbtree_,name,_pop)) \
|
||||
GET_MIN(CAT3(rbtree_,name,_min)), \
|
||||
GET_MAX(CAT3(rbtree_,name,_max)) \
|
||||
(INIT(M_C3(rbtree_, name, _init)), \
|
||||
INIT_SET(M_C3(rbtree_, name, _init_set)), \
|
||||
SET(M_C3(rbtree_, name, _set)), \
|
||||
CLEAR(M_C3(rbtree_, name, _clear)), \
|
||||
INIT_MOVE(M_C3(rbtree_, name, _init_move)), \
|
||||
MOVE(M_C3(rbtree_, name, _move)), \
|
||||
TYPE(M_C3(rbtree_,name,_t)), \
|
||||
SUBTYPE(M_C3(rbtree_type_,name,_t)), \
|
||||
IT_TYPE(M_C3(rbtree_it_,name,_t)), \
|
||||
IT_FIRST(M_C3(rbtree_,name,_it)), \
|
||||
IT_SET(M_C3(rbtree_,name,_it_set)), \
|
||||
IT_END_P(M_C3(rbtree_,name,_end_p)), \
|
||||
IT_LAST_P(M_C3(rbtree_,name,_last_p)), \
|
||||
IT_EQUAL_P(M_C3(rbtree_,name,_it_equal_p)), \
|
||||
IT_NEXT(M_C3(rbtree_,name,_next)), \
|
||||
IT_REF(M_C3(rbtree_,name,_ref)), \
|
||||
IT_CREF(M_C3(rbtree_,name,_cref)), \
|
||||
CLEAN(M_C3(rbtree_,name,_clean)), \
|
||||
PUSH(M_C3(rbtree_,name,_push)), \
|
||||
POP(M_C3(rbtree_,name,_pop)) \
|
||||
GET_MIN(M_C3(rbtree_,name,_min)), \
|
||||
GET_MAX(M_C3(rbtree_,name,_max)) \
|
||||
)
|
||||
|
||||
/* Max depth of the binary tree
|
||||
@@ -116,7 +116,7 @@ typedef enum {
|
||||
rbtreei_color_e color; \
|
||||
}; \
|
||||
\
|
||||
typedef struct CAT3(rbtree_, name, _s) { \
|
||||
typedef struct M_C3(rbtree_, name, _s) { \
|
||||
size_t size; \
|
||||
node_t *node; \
|
||||
} tree_t[1]; \
|
||||
@@ -125,25 +125,25 @@ typedef enum {
|
||||
node_t *stack[RBTREEI_MAX_STACK]; \
|
||||
char which[RBTREEI_MAX_STACK]; \
|
||||
unsigned int cpt; \
|
||||
} CAT3(rbtree_it_, name, _t)[1]; \
|
||||
} M_C3(rbtree_it_, name, _t)[1]; \
|
||||
\
|
||||
typedef type CAT3(rbtree_type_, name, _t); \
|
||||
typedef type M_C3(rbtree_type_, name, _t); \
|
||||
\
|
||||
typedef union { \
|
||||
type *ptr; \
|
||||
const type *cptr; \
|
||||
} CAT3(rbtree_union_, name,_t); \
|
||||
} M_C3(rbtree_union_, name,_t); \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(rbtree_, name, _const_cast)(type *ptr) \
|
||||
M_C3(rbtree_, name, _const_cast)(type *ptr) \
|
||||
{ \
|
||||
CAT3(rbtree_union_, name,_t) u; \
|
||||
M_C3(rbtree_union_, name,_t) u; \
|
||||
u.ptr = ptr; \
|
||||
return u.cptr; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _init)(tree_t tree) \
|
||||
M_C3(rbtree_, name, _init)(tree_t tree) \
|
||||
{ \
|
||||
assert (tree != NULL); \
|
||||
tree->size = 0; \
|
||||
@@ -152,7 +152,7 @@ typedef enum {
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _clear)(tree_t tree) \
|
||||
M_C3(rbtree_, name, _clear)(tree_t tree) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT(tree); \
|
||||
node_t *stack[RBTREEI_MAX_STACK]; \
|
||||
@@ -187,7 +187,7 @@ typedef enum {
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _push)(tree_t tree, type const data) \
|
||||
M_C3(rbtree_, name, _push)(tree_t tree, type const data) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT(tree); \
|
||||
node_t *tab[RBTREEI_MAX_STACK]; \
|
||||
@@ -316,15 +316,15 @@ typedef enum {
|
||||
} \
|
||||
\
|
||||
static inline size_t \
|
||||
CAT3(rbtree_, name, _size)(const tree_t tree) \
|
||||
M_C3(rbtree_, name, _size)(const tree_t tree) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
return tree->size; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtreei_, name, _it)(CAT3(rbtree_it_, name,_t) it, \
|
||||
const CAT3(rbtree_, name,_t) tree, int child) \
|
||||
M_C3(rbtreei_, name, _it)(M_C3(rbtree_it_, name,_t) it, \
|
||||
const M_C3(rbtree_, name,_t) tree, int child) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
assert (it != NULL); \
|
||||
@@ -344,28 +344,28 @@ typedef enum {
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _it)(CAT3(rbtree_it_, name,_t) it, \
|
||||
const CAT3(rbtree_, name,_t) tree) \
|
||||
M_C3(rbtree_, name, _it)(M_C3(rbtree_it_, name,_t) it, \
|
||||
const M_C3(rbtree_, name,_t) tree) \
|
||||
{ \
|
||||
CAT3(rbtreei_, name, _it)(it, tree, 0); \
|
||||
M_C3(rbtreei_, name, _it)(it, tree, 0); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _it_last)(CAT3(rbtree_it_, name,_t) it, \
|
||||
const CAT3(rbtree_, name,_t) tree) \
|
||||
M_C3(rbtree_, name, _it_last)(M_C3(rbtree_it_, name,_t) it, \
|
||||
const M_C3(rbtree_, name,_t) tree) \
|
||||
{ \
|
||||
CAT3(rbtreei_, name, _it)(it, tree, 1); \
|
||||
M_C3(rbtreei_, name, _it)(it, tree, 1); \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(rbtree_, name, _end_p)(const CAT3(rbtree_it_, name,_t) it) \
|
||||
M_C3(rbtree_, name, _end_p)(const M_C3(rbtree_it_, name,_t) it) \
|
||||
{ \
|
||||
assert (it != NULL); \
|
||||
return it->cpt == 0; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtreei_, name, _next)(CAT3(rbtree_it_, name,_t) it, int child) \
|
||||
M_C3(rbtreei_, name, _next)(M_C3(rbtree_it_, name,_t) it, int child) \
|
||||
{ \
|
||||
assert (it != NULL); \
|
||||
assert (child == 0 || child == 1); \
|
||||
@@ -395,40 +395,40 @@ typedef enum {
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _next)(CAT3(rbtree_it_, name,_t) it) \
|
||||
M_C3(rbtree_, name, _next)(M_C3(rbtree_it_, name,_t) it) \
|
||||
{ \
|
||||
CAT3(rbtreei_, name, _next)(it, 0); \
|
||||
M_C3(rbtreei_, name, _next)(it, 0); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _previous)(CAT3(rbtree_it_, name,_t) it) \
|
||||
M_C3(rbtree_, name, _previous)(M_C3(rbtree_it_, name,_t) it) \
|
||||
{ \
|
||||
CAT3(rbtreei_, name, _next)(it, 1); \
|
||||
M_C3(rbtreei_, name, _next)(it, 1); \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(rbtree_, name, _ref)(const CAT3(rbtree_it_, name,_t) it) \
|
||||
M_C3(rbtree_, name, _ref)(const M_C3(rbtree_it_, name,_t) it) \
|
||||
{ \
|
||||
assert(it != NULL && it->cpt > 0); \
|
||||
return &(it->stack[it->cpt-1]->data); \
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(rbtree_, name, _cref)(const CAT3(rbtree_it_, name,_t) it) \
|
||||
M_C3(rbtree_, name, _cref)(const M_C3(rbtree_it_, name,_t) it) \
|
||||
{ \
|
||||
return CAT3(rbtree_, name, _const_cast)(CAT3(rbtree_, name, _ref)(it)); \
|
||||
return M_C3(rbtree_, name, _const_cast)(M_C3(rbtree_, name, _ref)(it)); \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(rbtree_, name, _it_equal_p)(const CAT3(rbtree_it_, name,_t) it1, \
|
||||
const CAT3(rbtree_it_, name,_t) it2) \
|
||||
M_C3(rbtree_, name, _it_equal_p)(const M_C3(rbtree_it_, name,_t) it1, \
|
||||
const M_C3(rbtree_it_, name,_t) it2) \
|
||||
{ \
|
||||
return it1->cpt == it2->cpt \
|
||||
&& it1->stack[it1->cpt-1] == it2->stack[it2->cpt-1]; \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(rbtree_, name, _min)(const CAT3(rbtree_, name,_t) tree) \
|
||||
M_C3(rbtree_, name, _min)(const M_C3(rbtree_, name,_t) tree) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
node_t *n = tree->node; \
|
||||
@@ -441,7 +441,7 @@ typedef enum {
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(rbtree_, name, _max)(const CAT3(rbtree_, name,_t) tree) \
|
||||
M_C3(rbtree_, name, _max)(const M_C3(rbtree_, name,_t) tree) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
node_t *n = tree->node; \
|
||||
@@ -454,19 +454,19 @@ typedef enum {
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(rbtree_, name, _cmin)(const CAT3(rbtree_, name,_t) tree) \
|
||||
M_C3(rbtree_, name, _cmin)(const M_C3(rbtree_, name,_t) tree) \
|
||||
{ \
|
||||
return CAT3(rbtree_, name, _const_cast)(CAT3(rbtree_, name, _min)(tree)); \
|
||||
return M_C3(rbtree_, name, _const_cast)(M_C3(rbtree_, name, _min)(tree)); \
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(rbtree_, name, _cmax)(const CAT3(rbtree_, name,_t) tree) \
|
||||
M_C3(rbtree_, name, _cmax)(const M_C3(rbtree_, name,_t) tree) \
|
||||
{ \
|
||||
return CAT3(rbtree_, name, _const_cast)(CAT3(rbtree_, name, _max)(tree)); \
|
||||
return M_C3(rbtree_, name, _const_cast)(M_C3(rbtree_, name, _max)(tree)); \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(rbtree_, name, _get)(const tree_t tree, type const data) \
|
||||
M_C3(rbtree_, name, _get)(const tree_t tree, type const data) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
node_t *n = tree->node; \
|
||||
@@ -485,46 +485,46 @@ typedef enum {
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(rbtree_, name, _cget)(const CAT3(rbtree_, name,_t) tree, \
|
||||
M_C3(rbtree_, name, _cget)(const M_C3(rbtree_, name,_t) tree, \
|
||||
type const data) \
|
||||
{ \
|
||||
return CAT3(rbtree_, name, _const_cast)(CAT3(rbtree_, name, _get)(tree, data)); \
|
||||
return M_C3(rbtree_, name, _const_cast)(M_C3(rbtree_, name, _get)(tree, data)); \
|
||||
} \
|
||||
\
|
||||
static inline node_t * \
|
||||
CAT3(rbtreei_,name,_copyn)(const node_t *o) \
|
||||
M_C3(rbtreei_,name,_copyn)(const node_t *o) \
|
||||
{ \
|
||||
if (o == NULL) return NULL; \
|
||||
node_t *n = M_MEMORY_ALLOC(node_t); \
|
||||
M_GET_INIT_SET oplist (n->data, o->data); \
|
||||
n->child[0] = CAT3(rbtreei_,name,_copyn)(o->child[0]); \
|
||||
n->child[1] = CAT3(rbtreei_,name,_copyn)(o->child[1]); \
|
||||
n->child[0] = M_C3(rbtreei_,name,_copyn)(o->child[0]); \
|
||||
n->child[1] = M_C3(rbtreei_,name,_copyn)(o->child[1]); \
|
||||
RBTREEI_COPY_COLOR (n, o); \
|
||||
return n; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _init_set)(tree_t tree, const tree_t ref) \
|
||||
M_C3(rbtree_, name, _init_set)(tree_t tree, const tree_t ref) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (ref); \
|
||||
assert (tree != NULL && tree != ref); \
|
||||
tree->size = ref->size; \
|
||||
tree->node = CAT3(rbtreei_,name,_copyn)(ref->node); \
|
||||
tree->node = M_C3(rbtreei_,name,_copyn)(ref->node); \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _set)(tree_t tree, const tree_t ref) \
|
||||
M_C3(rbtree_, name, _set)(tree_t tree, const tree_t ref) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
RBTREEI_CONTRACT (ref); \
|
||||
if (tree == ref) return; \
|
||||
CAT3(rbtree_,name,_clear)(tree); \
|
||||
CAT3(rbtree_,name,_init_set)(tree, ref); \
|
||||
M_C3(rbtree_,name,_clear)(tree); \
|
||||
M_C3(rbtree_,name,_init_set)(tree, ref); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _init_move)(tree_t tree, tree_t ref) \
|
||||
M_C3(rbtree_, name, _init_move)(tree_t tree, tree_t ref) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (ref); \
|
||||
assert (tree != NULL && tree != ref); \
|
||||
@@ -536,37 +536,37 @@ typedef enum {
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtree_, name, _move)(tree_t tree, tree_t ref) \
|
||||
M_C3(rbtree_, name, _move)(tree_t tree, tree_t ref) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
RBTREEI_CONTRACT (ref); \
|
||||
assert (tree != ref); \
|
||||
CAT3(rbtree_,name,_clear)(tree); \
|
||||
CAT3(rbtree_,name,_init_move)(tree, ref); \
|
||||
M_C3(rbtree_,name,_clear)(tree); \
|
||||
M_C3(rbtree_,name,_init_move)(tree, ref); \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(rbtree_, name, _empty_p)(const tree_t tree) \
|
||||
M_C3(rbtree_, name, _empty_p)(const tree_t tree) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
return tree->size == 0; \
|
||||
} \
|
||||
\
|
||||
static inline rbtreei_color_e \
|
||||
CAT3(rbtreei_, name, _get_color)(const node_t *n) \
|
||||
M_C3(rbtreei_, name, _get_color)(const node_t *n) \
|
||||
{ \
|
||||
return (n == NULL) ? RBTREE_BLACK : n->color; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(rbtreei_, name, _set_color)(node_t *n, rbtreei_color_e c) \
|
||||
M_C3(rbtreei_, name, _set_color)(node_t *n, rbtreei_color_e c) \
|
||||
{ \
|
||||
if (n != NULL) n->color = c; \
|
||||
} \
|
||||
\
|
||||
static inline node_t * \
|
||||
CAT3(rbtreei_, name, _rotate)(node_t *pp, node_t *ppp, const bool right) \
|
||||
M_C3(rbtreei_, name, _rotate)(node_t *pp, node_t *ppp, const bool right) \
|
||||
{ \
|
||||
assert (pp != NULL && ppp != NULL); \
|
||||
bool left = !right; \
|
||||
@@ -581,15 +581,15 @@ typedef enum {
|
||||
} \
|
||||
\
|
||||
static size_t \
|
||||
CAT3(rbtreei_,name,_depth)(const node_t *n) \
|
||||
M_C3(rbtreei_,name,_depth)(const node_t *n) \
|
||||
{ \
|
||||
if (n == NULL) return 1; \
|
||||
return (n->color == RBTREE_BLACK) \
|
||||
+ CAT3(rbtreei_,name,_depth)(n->child[0]); \
|
||||
+ M_C3(rbtreei_,name,_depth)(n->child[0]); \
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(rbtree_, name, _pop)(type *data_ptr, tree_t tree, type const key) \
|
||||
M_C3(rbtree_, name, _pop)(type *data_ptr, tree_t tree, type const key) \
|
||||
{ \
|
||||
RBTREEI_CONTRACT (tree); \
|
||||
node_t *tab[RBTREEI_MAX_STACK]; \
|
||||
@@ -602,8 +602,8 @@ typedef enum {
|
||||
tab[cpt] = n; \
|
||||
while (n != NULL) { \
|
||||
RBTREEI_CONTRACT_NODE (n); \
|
||||
assert(CAT3(rbtreei_,name,_depth)(n->child[0]) \
|
||||
== CAT3(rbtreei_,name,_depth)(n->child[1])); \
|
||||
assert(M_C3(rbtreei_,name,_depth)(n->child[0]) \
|
||||
== M_C3(rbtreei_,name,_depth)(n->child[1])); \
|
||||
int cmp = M_GET_CMP oplist (n->data, key); \
|
||||
if (cmp == 0) { \
|
||||
break; \
|
||||
@@ -633,8 +633,8 @@ typedef enum {
|
||||
while (v != NULL) { \
|
||||
/* Always left node */ \
|
||||
RBTREEI_CONTRACT_NODE (v); \
|
||||
assert(CAT3(rbtreei_,name,_depth)(v->child[0]) \
|
||||
== CAT3(rbtreei_,name,_depth)(v->child[1])); \
|
||||
assert(M_C3(rbtreei_,name,_depth)(v->child[0]) \
|
||||
== M_C3(rbtreei_,name,_depth)(v->child[1])); \
|
||||
which[cpt++] = 0; \
|
||||
v = v->child[0]; \
|
||||
assert (cpt < RBTREEI_MAX_STACK); \
|
||||
@@ -669,7 +669,7 @@ typedef enum {
|
||||
\
|
||||
/* Rebalance from child to root */ \
|
||||
if (v_color == RBTREE_BLACK \
|
||||
&& CAT3(rbtreei_,name,_get_color)(u) == RBTREE_BLACK) { \
|
||||
&& M_C3(rbtreei_,name,_get_color)(u) == RBTREE_BLACK) { \
|
||||
/* tab[0] is NULL, tab[1] is root, u is double black */ \
|
||||
node_t *p = u, *s; \
|
||||
while (cpt >= 2) { \
|
||||
@@ -678,8 +678,8 @@ typedef enum {
|
||||
assert (p != NULL && u == p->child[nbChild]); \
|
||||
s = p->child[!nbChild]; \
|
||||
/* if sibling is red, perform a rotation to move sibling up */ \
|
||||
if (CAT3(rbtreei_,name,_get_color)(s) == RBTREE_RED) { \
|
||||
p = CAT3(rbtreei_,name,_rotate) (p, tab[cpt-1], !nbChild); \
|
||||
if (M_C3(rbtreei_,name,_get_color)(s) == RBTREE_RED) { \
|
||||
p = M_C3(rbtreei_,name,_rotate) (p, tab[cpt-1], !nbChild); \
|
||||
p->color = RBTREE_BLACK; /* was sibling */ \
|
||||
tab[cpt] = p; \
|
||||
which[cpt++] = nbChild; \
|
||||
@@ -687,20 +687,20 @@ typedef enum {
|
||||
assert (p != NULL); \
|
||||
p->color = RBTREE_RED; \
|
||||
s = p->child[!nbChild]; \
|
||||
assert (CAT3(rbtreei_,name,_get_color)(s) == RBTREE_BLACK); \
|
||||
assert (M_C3(rbtreei_,name,_get_color)(s) == RBTREE_BLACK); \
|
||||
} \
|
||||
assert (p != NULL && u == p->child[nbChild]); \
|
||||
/* if both childreen of s are black */ \
|
||||
/* perform recoloring and recur on parent if black */ \
|
||||
if (s != NULL \
|
||||
&& CAT3(rbtreei_,name,_get_color)(s->child[0])== RBTREE_BLACK \
|
||||
&& CAT3(rbtreei_,name,_get_color)(s->child[1])== RBTREE_BLACK) { \
|
||||
assert(CAT3(rbtreei_,name,_depth)(s->child[0]) == CAT3(rbtreei_,name,_depth)(s->child[1])); \
|
||||
&& M_C3(rbtreei_,name,_get_color)(s->child[0])== RBTREE_BLACK \
|
||||
&& M_C3(rbtreei_,name,_get_color)(s->child[1])== RBTREE_BLACK) { \
|
||||
assert(M_C3(rbtreei_,name,_depth)(s->child[0]) == M_C3(rbtreei_,name,_depth)(s->child[1])); \
|
||||
s->color = RBTREE_RED; \
|
||||
if (p->color == RBTREE_RED) { \
|
||||
p->color = RBTREE_BLACK; \
|
||||
RBTREEI_CONTRACT_NODE(p); \
|
||||
assert(CAT3(rbtreei_,name,_depth)(p->child[0]) == CAT3(rbtreei_,name,_depth)(p->child[1])); \
|
||||
assert(M_C3(rbtreei_,name,_depth)(p->child[0]) == M_C3(rbtreei_,name,_depth)(p->child[1])); \
|
||||
break; \
|
||||
} \
|
||||
u = p; \
|
||||
@@ -708,30 +708,30 @@ typedef enum {
|
||||
assert (s != NULL); \
|
||||
/* at least one child of 's' is red */ \
|
||||
/* perform rotation(s) */ \
|
||||
bool childIsRight = CAT3(rbtreei_,name,_get_color)(s->child[1])== RBTREE_RED; \
|
||||
bool childIsRight = M_C3(rbtreei_,name,_get_color)(s->child[1])== RBTREE_RED; \
|
||||
rbtreei_color_e p_color = p->color; \
|
||||
if (childIsRight != nbChild) { \
|
||||
/* left-left or right-right case */ \
|
||||
p = CAT3(rbtreei_,name,_rotate) (p, tab[cpt-1], childIsRight); \
|
||||
p = M_C3(rbtreei_,name,_rotate) (p, tab[cpt-1], childIsRight); \
|
||||
} else { \
|
||||
s = CAT3(rbtreei_,name,_rotate) (s, p, childIsRight); \
|
||||
p = CAT3(rbtreei_,name,_rotate) (p, tab[cpt-1], !nbChild); \
|
||||
s = M_C3(rbtreei_,name,_rotate) (s, p, childIsRight); \
|
||||
p = M_C3(rbtreei_,name,_rotate) (p, tab[cpt-1], !nbChild); \
|
||||
} \
|
||||
p->color = p_color; \
|
||||
assert(p->child[0] != NULL && p->child[1] != NULL); \
|
||||
p->child[0]->color = RBTREE_BLACK; \
|
||||
p->child[1]->color = RBTREE_BLACK; \
|
||||
RBTREEI_CONTRACT_NODE(p); \
|
||||
assert(CAT3(rbtreei_,name,_depth)(p->child[0]) == CAT3(rbtreei_,name,_depth)(p->child[1])); \
|
||||
assert(M_C3(rbtreei_,name,_depth)(p->child[0]) == M_C3(rbtreei_,name,_depth)(p->child[1])); \
|
||||
break; \
|
||||
} \
|
||||
} /* while */ \
|
||||
if (cpt == 1 /* root has been reached? */ ) { \
|
||||
CAT3(rbtreei_,name,_set_color)(p, RBTREE_BLACK); \
|
||||
M_C3(rbtreei_,name,_set_color)(p, RBTREE_BLACK); \
|
||||
assert (tree->node == p); \
|
||||
} \
|
||||
} else { \
|
||||
CAT3(rbtreei_,name,_set_color)(u, RBTREE_BLACK); \
|
||||
M_C3(rbtreei_,name,_set_color)(u, RBTREE_BLACK); \
|
||||
} \
|
||||
assert (tree->node == NULL || tree->node->color == RBTREE_BLACK); \
|
||||
/* delete it */ \
|
||||
|
||||
+10
-10
@@ -36,8 +36,8 @@
|
||||
|
||||
// TODO: Iterator shall also be considered as key
|
||||
#define M_METHOD_EXPAND(method, id) \
|
||||
CAT3(CLASS_,id,_TYPE)*: CAT3(CLASS_,id,_DEFINITION).method, \
|
||||
const CAT3(CLASS_,id,_TYPE)*: CAT3(CLASS_,id,_DEFINITION).method
|
||||
M_C3(CLASS_,id,_TYPE)*: M_C3(CLASS_,id,_DEFINITION).method, \
|
||||
const M_C3(CLASS_,id,_TYPE)*: M_C3(CLASS_,id,_DEFINITION).method
|
||||
|
||||
// TODO: How to define Default method if there is no registered method?
|
||||
// the current way may produce syntaxically invalid C due to macro expanding to
|
||||
@@ -50,12 +50,12 @@
|
||||
_Generic(&(M_RET_ARG2(__VA_ARGS__, )), \
|
||||
M_SEQ2(0,DEC(CLASS_CPT),M_METHOD_EXPAND, method))(__VA_ARGS__) \
|
||||
|
||||
#define M_CLASS_DEFINE_FIELD(a) M_APPLY(M_CLASS_DEFINE_FIELD0 , CAT(M_PROTO_TUPLE_, a))
|
||||
#define M_CLASS_M_GET_FUNCPTR(a) M_APPLY(M_CLASS_M_GET_FUNCPTR0, CAT(M_PROTO_TUPLE_, a))
|
||||
#define M_CLASS_DEFINE_TYPE(a) M_APPLY(M_CLASS_DEFINE_TYPE0 , CAT(M_PROTO_TUPLE_, a))
|
||||
#define M_CLASS_DEFINE_FIELD0(a, b) M_IF(M_BOOL(CAT(M_PROTO_ISMETHOD_, a)))(CAT(M_PROTO_METHOD_, a)(TYPE, a);,/*nothing*/)
|
||||
#define M_CLASS_M_GET_FUNCPTR0(a,b) M_IF(M_BOOL(CAT(M_PROTO_ISMETHOD_, a)))(.a = b M_DEFERRED_COMMA, /*nothing*/)
|
||||
#define M_CLASS_DEFINE_TYPE0(a, b) M_IF(M_BOOL(CAT(M_PROTO_ISMETHOD_, a)))(/*nothing*/, typedef b CAT(TYPE_, a);)
|
||||
#define M_CLASS_DEFINE_FIELD(a) M_APPLY(M_CLASS_DEFINE_FIELD0 , M_C(M_PROTO_TUPLE_, a))
|
||||
#define M_CLASS_M_GET_FUNCPTR(a) M_APPLY(M_CLASS_M_GET_FUNCPTR0, M_C(M_PROTO_TUPLE_, a))
|
||||
#define M_CLASS_DEFINE_TYPE(a) M_APPLY(M_CLASS_DEFINE_TYPE0 , M_C(M_PROTO_TUPLE_, a))
|
||||
#define M_CLASS_DEFINE_FIELD0(a, b) M_IF(M_BOOL(M_C(M_PROTO_ISMETHOD_, a)))(M_C(M_PROTO_METHOD_, a)(TYPE, a);,/*nothing*/)
|
||||
#define M_CLASS_M_GET_FUNCPTR0(a,b) M_IF(M_BOOL(M_C(M_PROTO_ISMETHOD_, a)))(.a = b M_DEFERRED_COMMA, /*nothing*/)
|
||||
#define M_CLASS_DEFINE_TYPE0(a, b) M_IF(M_BOOL(M_C(M_PROTO_ISMETHOD_, a)))(/*nothing*/, typedef b M_C(TYPE_, a);)
|
||||
|
||||
/* Define basic supported methods and types */
|
||||
#define M_PROTO_TUPLE_INIT(value) INIT, value
|
||||
@@ -75,8 +75,8 @@
|
||||
#define M_PROTO_METHOD_SET(type, alias) void (*alias)(type, const type)
|
||||
#define M_PROTO_METHOD_CLEAR(type, alias) void (*alias)(type)
|
||||
#define M_PROTO_METHOD_EQUAL(type, alias) bool (*alias)(const type, const type)
|
||||
#define M_PROTO_METHOD_PUSH(type, alias) void (*alias)(type, const CAT(type, _TYPE))
|
||||
#define M_PROTO_METHOD_POP(type, alias) void (*alias)(CAT(type, _TYPE)*, type)
|
||||
#define M_PROTO_METHOD_PUSH(type, alias) void (*alias)(type, const M_C(type, _TYPE))
|
||||
#define M_PROTO_METHOD_POP(type, alias) void (*alias)(M_C(type, _TYPE)*, type)
|
||||
#define M_PROTO_METHOD_PRINT(type, alias) void (*alias)(const type)
|
||||
#define M_PROTO_METHOD_TOSTR(type, alias) void (*alias)(string_t, const type)
|
||||
|
||||
|
||||
+35
-35
@@ -34,12 +34,12 @@
|
||||
#include "m-core.h"
|
||||
|
||||
#define SHARED_PTR_OPLIST(name) ( \
|
||||
INIT(CAT3(shared_, name, _init)), \
|
||||
CLEAR(CAT3(shared_, name, _clear)), \
|
||||
INIT_SET(CAT3(shared_, name, _init_set)), \
|
||||
SET(CAT3(shared_, name, _set)) \
|
||||
INIT_MOVE(CAT3(shared_, name, _init_move)), \
|
||||
MOVE(CAT3(shared_, name, _move)) \
|
||||
INIT(M_C3(shared_, name, _init)), \
|
||||
CLEAR(M_C3(shared_, name, _clear)), \
|
||||
INIT_SET(M_C3(shared_, name, _init_set)), \
|
||||
SET(M_C3(shared_, name, _set)) \
|
||||
INIT_MOVE(M_C3(shared_, name, _init_move)), \
|
||||
MOVE(M_C3(shared_, name, _move)) \
|
||||
)
|
||||
|
||||
#define SHARED_PTR_DEF(name, ...) \
|
||||
@@ -50,41 +50,41 @@
|
||||
/********************************** INTERNAL ************************************/
|
||||
|
||||
#define SHAREDI_PTR_DEF2(name, type, oplist) \
|
||||
typedef struct CAT3(shared_, name, _s){ \
|
||||
typedef struct M_C3(shared_, name, _s){ \
|
||||
int cpt; \
|
||||
type *data; \
|
||||
} *CAT3(shared_, name, _t)[1]; \
|
||||
} *M_C3(shared_, name, _t)[1]; \
|
||||
\
|
||||
typedef union { \
|
||||
type *ptr; \
|
||||
const type *cptr; \
|
||||
} CAT3(shared_union_, name,_t); \
|
||||
} M_C3(shared_union_, name,_t); \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(shared_, name, _const_cast)(type *ptr) \
|
||||
M_C3(shared_, name, _const_cast)(type *ptr) \
|
||||
{ \
|
||||
CAT3(shared_union_, name,_t) u; \
|
||||
M_C3(shared_union_, name,_t) u; \
|
||||
u.ptr = ptr; \
|
||||
return u.cptr; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(shared_, name, _init)(CAT3(shared_, name, _t) shared) \
|
||||
M_C3(shared_, name, _init)(M_C3(shared_, name, _t) shared) \
|
||||
{ \
|
||||
*shared = NULL; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(shared_, name, _init2)(CAT3(shared_, name, _t) shared, type *data) \
|
||||
M_C3(shared_, name, _init2)(M_C3(shared_, name, _t) shared, type *data) \
|
||||
{ \
|
||||
struct CAT3(shared_, name, _s) *ptr; \
|
||||
struct M_C3(shared_, name, _s) *ptr; \
|
||||
if (data == NULL) { \
|
||||
*shared = NULL; \
|
||||
return; \
|
||||
} \
|
||||
ptr = M_MEMORY_ALLOC (struct CAT3(shared_, name, _s)); \
|
||||
ptr = M_MEMORY_ALLOC (struct M_C3(shared_, name, _s)); \
|
||||
if (ptr == NULL) \
|
||||
M_MEMORY_FULL(sizeof(struct CAT3(shared_, name, _s))); \
|
||||
M_MEMORY_FULL(sizeof(struct M_C3(shared_, name, _s))); \
|
||||
ptr->cpt = 1; \
|
||||
ptr->data = data; \
|
||||
*shared = ptr; \
|
||||
@@ -92,15 +92,15 @@
|
||||
} \
|
||||
\
|
||||
static inline bool \
|
||||
CAT3(shared_, name, _NULL_p)(const CAT3(shared_, name, _t) shared) \
|
||||
M_C3(shared_, name, _NULL_p)(const M_C3(shared_, name, _t) shared) \
|
||||
{ \
|
||||
SHAREDI_CONTRACT(shared); \
|
||||
return *shared == NULL; \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(shared_, name, _init_set)(CAT3(shared_, name, _t) dest, \
|
||||
const CAT3(shared_, name, _t) shared) \
|
||||
M_C3(shared_, name, _init_set)(M_C3(shared_, name, _t) dest, \
|
||||
const M_C3(shared_, name, _t) shared) \
|
||||
{ \
|
||||
SHAREDI_CONTRACT(shared); \
|
||||
assert (dest != shared); \
|
||||
@@ -111,7 +111,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(shared_, name, _release)(CAT3(shared_, name, _t) dest) \
|
||||
M_C3(shared_, name, _release)(M_C3(shared_, name, _t) dest) \
|
||||
{ \
|
||||
SHAREDI_CONTRACT(dest); \
|
||||
if (*dest != NULL) { \
|
||||
@@ -126,25 +126,25 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(shared_, name, _clear)(CAT3(shared_, name, _t) dest) \
|
||||
M_C3(shared_, name, _clear)(M_C3(shared_, name, _t) dest) \
|
||||
{ \
|
||||
SHAREDI_CONTRACT(dest); \
|
||||
CAT3(shared_, name, _release)(dest); \
|
||||
M_C3(shared_, name, _release)(dest); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(shared_, name, _set)(CAT3(shared_, name, _t) dest, \
|
||||
const CAT3(shared_, name, _t) shared) \
|
||||
M_C3(shared_, name, _set)(M_C3(shared_, name, _t) dest, \
|
||||
const M_C3(shared_, name, _t) shared) \
|
||||
{ \
|
||||
SHAREDI_CONTRACT(dest); \
|
||||
SHAREDI_CONTRACT(shared); \
|
||||
CAT3(shared_, name, _release)(dest); \
|
||||
CAT3(shared_, name, _init_set)(dest, shared); \
|
||||
M_C3(shared_, name, _release)(dest); \
|
||||
M_C3(shared_, name, _init_set)(dest, shared); \
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(shared_, name, _init_move)(CAT3(shared_, name, _t) dest, \
|
||||
CAT3(shared_, name, _t) shared) \
|
||||
M_C3(shared_, name, _init_move)(M_C3(shared_, name, _t) dest, \
|
||||
M_C3(shared_, name, _t) shared) \
|
||||
{ \
|
||||
SHAREDI_CONTRACT(shared); \
|
||||
assert (dest != NULL && dest != shared); \
|
||||
@@ -154,25 +154,25 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
CAT3(shared_, name, _move)(CAT3(shared_, name, _t) dest, \
|
||||
CAT3(shared_, name, _t) shared) \
|
||||
M_C3(shared_, name, _move)(M_C3(shared_, name, _t) dest, \
|
||||
M_C3(shared_, name, _t) shared) \
|
||||
{ \
|
||||
SHAREDI_CONTRACT(dest); \
|
||||
SHAREDI_CONTRACT(shared); \
|
||||
assert (dest != shared); \
|
||||
CAT3(shared_, name, _clear)(dest); \
|
||||
CAT3(shared_, name, _init_move)(dest, shared); \
|
||||
M_C3(shared_, name, _clear)(dest); \
|
||||
M_C3(shared_, name, _init_move)(dest, shared); \
|
||||
} \
|
||||
\
|
||||
static inline const type * \
|
||||
CAT3(shared_, name, _cref)(const CAT3(shared_, name, _t) shared) \
|
||||
M_C3(shared_, name, _cref)(const M_C3(shared_, name, _t) shared) \
|
||||
{ \
|
||||
SHAREDI_CONTRACT(shared); \
|
||||
return CAT3(shared_, name, _const_cast) ((*shared)->data); \
|
||||
return M_C3(shared_, name, _const_cast) ((*shared)->data); \
|
||||
} \
|
||||
\
|
||||
static inline type * \
|
||||
CAT3(shared_, name, _ref)(CAT3(shared_, name, _t) shared) \
|
||||
M_C3(shared_, name, _ref)(M_C3(shared_, name, _t) shared) \
|
||||
{ \
|
||||
SHAREDI_CONTRACT(shared); \
|
||||
return (*shared)->data; \
|
||||
|
||||
+25
-25
@@ -47,14 +47,14 @@
|
||||
|
||||
/* Define the oplist of a snapshot */
|
||||
#define SNAPSHOTI_OPLIST(type, oplist) \
|
||||
(INIT(CAT3(snapshot_, type, _init)), \
|
||||
INIT_SET(CAT3(snapshot_, type, _init_set)), \
|
||||
SET(CAT3(snapshot_, type, _set)), \
|
||||
CLEAR(CAT3(snapshot_, type, _clear)), \
|
||||
TYPE(CAT3(snapshot_, type, _t)), \
|
||||
SUBTYPE(CAT3(snapshot_type_, name, _t)) \
|
||||
,M_IF_METHOD(INIT_MOVE, oplist)(INIT_MOVE(CAT3(snapshot_, name, _init_move)),) \
|
||||
,M_IF_METHOD(MOVE, oplist)(MOVE(CAT3(snapshot_, name, _move)),) \
|
||||
(INIT(M_C3(snapshot_, type, _init)), \
|
||||
INIT_SET(M_C3(snapshot_, type, _init_set)), \
|
||||
SET(M_C3(snapshot_, type, _set)), \
|
||||
CLEAR(M_C3(snapshot_, type, _clear)), \
|
||||
TYPE(M_C3(snapshot_, type, _t)), \
|
||||
SUBTYPE(M_C3(snapshot_type_, name, _t)) \
|
||||
,M_IF_METHOD(INIT_MOVE, oplist)(INIT_MOVE(M_C3(snapshot_, name, _init_move)),) \
|
||||
,M_IF_METHOD(MOVE, oplist)(MOVE(M_C3(snapshot_, name, _move)),) \
|
||||
)
|
||||
|
||||
#define SNAPSHOTI_FLAG(r, w, f, b) \
|
||||
@@ -78,13 +78,13 @@
|
||||
} while (0)
|
||||
|
||||
#define SNAPSHOTI_DEF2(name, type, oplist) \
|
||||
typedef struct CAT3(snapshot_, name, _s) { \
|
||||
typedef struct M_C3(snapshot_, name, _s) { \
|
||||
type data[3]; \
|
||||
atomic_uint_fast8_t flags; \
|
||||
} CAT3(snapshot_, name, _t)[1]; \
|
||||
typedef type CAT3(snapshot_type_, name, _t); \
|
||||
} M_C3(snapshot_, name, _t)[1]; \
|
||||
typedef type M_C3(snapshot_type_, name, _t); \
|
||||
\
|
||||
static inline void CAT3(snapshot_, name, _init)(CAT3(snapshot_, name, _t) snap) \
|
||||
static inline void M_C3(snapshot_, name, _init)(M_C3(snapshot_, name, _t) snap) \
|
||||
{ \
|
||||
assert(snap != NULL); \
|
||||
for(int i = 0; i < 3; i++) { \
|
||||
@@ -93,7 +93,7 @@
|
||||
snap->flags = ATOMIC_VAR_INIT (SNAPSHOTI_FLAG(0, 1, 2, 0)); \
|
||||
} \
|
||||
\
|
||||
static inline void CAT3(snapshot_, name, _clear)(CAT3(snapshot_, name, _t) snap) \
|
||||
static inline void M_C3(snapshot_, name, _clear)(M_C3(snapshot_, name, _t) snap) \
|
||||
{ \
|
||||
SNAPSHOTI_CONTRACT(snap); \
|
||||
for(int i = 0; i < 3; i++) { \
|
||||
@@ -101,8 +101,8 @@
|
||||
} \
|
||||
} \
|
||||
\
|
||||
static inline void CAT3(snapshot_, name, _init_set)(CAT3(snapshot_, name, _t) snap, \
|
||||
const CAT3(snapshot_, name, _t) org) \
|
||||
static inline void M_C3(snapshot_, name, _init_set)(M_C3(snapshot_, name, _t) snap, \
|
||||
const M_C3(snapshot_, name, _t) org) \
|
||||
{ \
|
||||
SNAPSHOTI_CONTRACT(org); \
|
||||
assert(snap != NULL && snap != org); \
|
||||
@@ -113,8 +113,8 @@
|
||||
SNAPSHOTI_CONTRACT(snap); \
|
||||
} \
|
||||
\
|
||||
static inline void CAT3(snapshot_, name, _set)(CAT3(snapshot_, name, _t) snap, \
|
||||
const CAT3(snapshot_, name, _t) org) \
|
||||
static inline void M_C3(snapshot_, name, _set)(M_C3(snapshot_, name, _t) snap, \
|
||||
const M_C3(snapshot_, name, _t) org) \
|
||||
{ \
|
||||
SNAPSHOTI_CONTRACT(snap); \
|
||||
SNAPSHOTI_CONTRACT(org); \
|
||||
@@ -126,8 +126,8 @@
|
||||
} \
|
||||
\
|
||||
M_IF_METHOD(INIT_MOVE, oplist)( \
|
||||
static inline void CAT3(snapshot_, name, _init_move)(CAT3(snapshot_, name, _t) snap, \
|
||||
CAT3(snapshot_, name, _t) org) \
|
||||
static inline void M_C3(snapshot_, name, _init_move)(M_C3(snapshot_, name, _t) snap, \
|
||||
M_C3(snapshot_, name, _t) org) \
|
||||
{ \
|
||||
SNAPSHOTI_CONTRACT(org); \
|
||||
assert(snap != NULL && snap != org); \
|
||||
@@ -141,8 +141,8 @@
|
||||
,) /* IF_METHOD (INIT_MOVE) */ \
|
||||
\
|
||||
M_IF_METHOD(MOVE, oplist)( \
|
||||
static inline void CAT3(snapshot_, name, _move)(CAT3(snapshot_, name, _t) snap, \
|
||||
CAT3(snapshot_, name, _t) org) \
|
||||
static inline void M_C3(snapshot_, name, _move)(M_C3(snapshot_, name, _t) snap, \
|
||||
M_C3(snapshot_, name, _t) org) \
|
||||
{ \
|
||||
SNAPSHOTI_CONTRACT(snap); \
|
||||
SNAPSHOTI_CONTRACT(org); \
|
||||
@@ -156,7 +156,7 @@
|
||||
} \
|
||||
,) /* IF_METHOD (MOVE) */ \
|
||||
\
|
||||
static inline type *CAT3(snapshot_, name, _take)(CAT3(snapshot_, name, _t) snap) \
|
||||
static inline type *M_C3(snapshot_, name, _take)(M_C3(snapshot_, name, _t) snap) \
|
||||
{ \
|
||||
SNAPSHOTI_CONTRACT(snap); \
|
||||
uint_fast8_t nextFlags, origFlags = atomic_load(&snap->flags); \
|
||||
@@ -169,7 +169,7 @@
|
||||
return &snap->data[SNAPSHOTI_W(nextFlags)]; \
|
||||
} \
|
||||
\
|
||||
static inline const type *CAT3(snapshot_, name, _look)(const CAT3(snapshot_, name, _t) snap) \
|
||||
static inline const type *M_C3(snapshot_, name, _look)(const M_C3(snapshot_, name, _t) snap) \
|
||||
{ \
|
||||
SNAPSHOTI_CONTRACT(snap); \
|
||||
uint_fast8_t nextFlags, origFlags = atomic_load(&snap->flags); \
|
||||
@@ -184,13 +184,13 @@
|
||||
return &snap->data[SNAPSHOTI_R(snap->flags)]; \
|
||||
} \
|
||||
\
|
||||
static inline type *CAT3(snapshot_, name, _get_produced)(CAT3(snapshot_, name, _t) snap) \
|
||||
static inline type *M_C3(snapshot_, name, _get_produced)(M_C3(snapshot_, name, _t) snap) \
|
||||
{ \
|
||||
SNAPSHOTI_CONTRACT(snap); \
|
||||
return &snap->data[SNAPSHOTI_W(snap->flags)]; \
|
||||
} \
|
||||
\
|
||||
static inline const type *CAT3(snapshot_, name, _get_consummed)(const CAT3(snapshot_, name, _t) snap) \
|
||||
static inline const type *M_C3(snapshot_, name, _get_consummed)(const M_C3(snapshot_, name, _t) snap) \
|
||||
{ \
|
||||
SNAPSHOTI_CONTRACT(snap); \
|
||||
return &snap->data[SNAPSHOTI_R(snap->flags)]; \
|
||||
|
||||
+1
-1
@@ -633,7 +633,7 @@ string_in_str(string_t v, FILE *f)
|
||||
}
|
||||
|
||||
#define STRING_SPLIT(name, oplist, type_oplist) \
|
||||
static inline void CAT(name, _split)(M_GET_TYPE oplist cont, \
|
||||
static inline void M_C(name, _split)(M_GET_TYPE oplist cont, \
|
||||
const string_t str, const char sep) \
|
||||
{ \
|
||||
size_t begin = 0; \
|
||||
|
||||
@@ -49,17 +49,17 @@
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_TYPE(name, ...) \
|
||||
typedef struct CAT(name, _s) { \
|
||||
typedef struct M_C(name, _s) { \
|
||||
M_MAP(TUPLE_DEFINE_RECUR_TYPE_ELE , __VA_ARGS__) \
|
||||
} CAT(name,_t)[1]; \
|
||||
typedef struct CAT(name, _s) *CAT(name, _ptr); \
|
||||
typedef const struct CAT(name, _s) *CAT(name, _srcptr);
|
||||
} M_C(name,_t)[1]; \
|
||||
typedef struct M_C(name, _s) *M_C(name, _ptr); \
|
||||
typedef const struct M_C(name, _s) *M_C(name, _srcptr);
|
||||
#define TUPLE_DEFINE_RECUR_TYPE_ELE(a) \
|
||||
TUPLE_GET_TYPE a TUPLE_GET_FIELD a ;
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_INIT(name, ...) \
|
||||
static inline void CAT(name, _init)(CAT(name,_t) my) { \
|
||||
static inline void M_C(name, _init)(M_C(name,_t) my) { \
|
||||
M_MAP(TUPLE_DEFINE_INIT_FUNC , __VA_ARGS__) \
|
||||
}
|
||||
#define TUPLE_DEFINE_INIT_FUNC(a) \
|
||||
@@ -67,7 +67,7 @@
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_INIT_SET(name, ...) \
|
||||
static inline void CAT(name, _init_set)(CAT(name,_t) my , CAT(name,_t) const org) { \
|
||||
static inline void M_C(name, _init_set)(M_C(name,_t) my , M_C(name,_t) const org) { \
|
||||
M_MAP(TUPLE_DEFINE_INIT_SET_FUNC , __VA_ARGS__) \
|
||||
}
|
||||
#define TUPLE_DEFINE_INIT_SET_FUNC(a) \
|
||||
@@ -75,7 +75,7 @@
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_INIT_SET2(name, ...) \
|
||||
static inline void CAT(name, _init_set2)(CAT(name,_t) my \
|
||||
static inline void M_C(name, _init_set2)(M_C(name,_t) my \
|
||||
M_MAP(TUPLE_DEFINE_INIT_SET2_PROTO, __VA_ARGS__) \
|
||||
) { \
|
||||
M_MAP(TUPLE_DEFINE_INIT_SET2_FUNC , __VA_ARGS__) \
|
||||
@@ -87,8 +87,8 @@
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_SET(name, ...) \
|
||||
static inline void CAT(name, _set)(CAT(name,_t) my , \
|
||||
CAT(name,_t) const org) { \
|
||||
static inline void M_C(name, _set)(M_C(name,_t) my , \
|
||||
M_C(name,_t) const org) { \
|
||||
M_MAP(TUPLE_DEFINE_SET_FUNC , __VA_ARGS__) \
|
||||
}
|
||||
#define TUPLE_DEFINE_SET_FUNC(a) \
|
||||
@@ -96,7 +96,7 @@
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_CLEAR(name, ...) \
|
||||
static inline void CAT(name, _clear)(CAT(name,_t) my) { \
|
||||
static inline void M_C(name, _clear)(M_C(name,_t) my) { \
|
||||
M_MAP(TUPLE_DEFINE_CLEAR_FUNC , __VA_ARGS__) \
|
||||
}
|
||||
#define TUPLE_DEFINE_CLEAR_FUNC(a) \
|
||||
@@ -106,22 +106,22 @@
|
||||
#define TUPLE_DEFINE_GETTER(name, ...) \
|
||||
M_MAP2(TUPLE_DEFINE_GETTER_PROTO, name, __VA_ARGS__)
|
||||
#define TUPLE_DEFINE_GETTER_PROTO(name, a) \
|
||||
static inline TUPLE_GET_TYPE a const * CAT3(name, _get_, TUPLE_GET_FIELD a) \
|
||||
(CAT(name,_t) const my) { \
|
||||
static inline TUPLE_GET_TYPE a const * M_C3(name, _get_, TUPLE_GET_FIELD a) \
|
||||
(M_C(name,_t) const my) { \
|
||||
return (TUPLE_GET_TYPE a const * ) &(my->TUPLE_GET_FIELD a);}
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_SETTER(name, ...) \
|
||||
M_MAP2(TUPLE_DEFINE_SETTER_PROTO, name, __VA_ARGS__)
|
||||
#define TUPLE_DEFINE_SETTER_PROTO(name, a) \
|
||||
static inline void CAT3(name, _set_, TUPLE_GET_FIELD a) \
|
||||
(CAT(name,_t) my, TUPLE_GET_TYPE a TUPLE_GET_FIELD a) { \
|
||||
static inline void M_C3(name, _set_, TUPLE_GET_FIELD a) \
|
||||
(M_C(name,_t) my, TUPLE_GET_TYPE a TUPLE_GET_FIELD a) { \
|
||||
TUPLE_GET_SET a (my ->TUPLE_GET_FIELD a, TUPLE_GET_FIELD a);}
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_CMP(name, ...) \
|
||||
static inline int CAT(name, _cmp)(CAT(name,_t) const e1 , \
|
||||
CAT(name,_t) const e2) { \
|
||||
static inline int M_C(name, _cmp)(M_C(name,_t) const e1 , \
|
||||
M_C(name,_t) const e2) { \
|
||||
int i; \
|
||||
M_MAP(TUPLE_DEFINE_CMP_FUNC , __VA_ARGS__) \
|
||||
return 0; \
|
||||
@@ -132,8 +132,8 @@
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_EQUAL(name, ...) \
|
||||
static inline bool CAT(name, _equal_p)(CAT(name,_t) const e1 , \
|
||||
CAT(name,_t) const e2) { \
|
||||
static inline bool M_C(name, _equal_p)(M_C(name,_t) const e1 , \
|
||||
M_C(name,_t) const e2) { \
|
||||
bool b; \
|
||||
M_MAP(TUPLE_DEFINE_EQUAL_FUNC , __VA_ARGS__) \
|
||||
return true; \
|
||||
@@ -144,7 +144,7 @@
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_HASH(name, ...) \
|
||||
static inline unsigned long CAT(name, _hash)(CAT(name,_t) const e1) { \
|
||||
static inline unsigned long M_C(name, _hash)(M_C(name,_t) const e1) { \
|
||||
unsigned long hash = 0; \
|
||||
M_MAP(TUPLE_DEFINE_HASH_FUNC , __VA_ARGS__) \
|
||||
return hash; \
|
||||
@@ -154,8 +154,8 @@
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_GET_STR(name, ...) \
|
||||
static inline void CAT(name, _get_str)(string_t str, \
|
||||
CAT(name,_t) const el, \
|
||||
static inline void M_C(name, _get_str)(string_t str, \
|
||||
M_C(name,_t) const el, \
|
||||
bool append) { \
|
||||
bool comma = false; \
|
||||
assert (str != NULL && el != NULL); \
|
||||
@@ -170,8 +170,8 @@
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_OUT_STR(name, ...) \
|
||||
static inline void CAT(name, _out_str)(FILE *f, \
|
||||
CAT(name,_t) const el) { \
|
||||
static inline void M_C(name, _out_str)(FILE *f, \
|
||||
M_C(name,_t) const el) { \
|
||||
bool comma = false; \
|
||||
assert (f != NULL && el != NULL); \
|
||||
fputc('(', f); \
|
||||
@@ -185,7 +185,7 @@
|
||||
|
||||
|
||||
#define TUPLE_DEFINE_IN_STR(name, ...) \
|
||||
static inline bool CAT(name, _in_str)(CAT(name,_t) el, FILE *f) { \
|
||||
static inline bool M_C(name, _in_str)(M_C(name,_t) el, FILE *f) { \
|
||||
bool comma = false; \
|
||||
assert (f != NULL && el != NULL); \
|
||||
char c = fgetc(f); \
|
||||
@@ -204,14 +204,14 @@
|
||||
return false ; \
|
||||
|
||||
#define TUPLE_DEFINE_INIT_MOVE(name, ...) \
|
||||
static inline void CAT(name, _init_move)(CAT(name,_t) el, CAT(name,_t) org) { \
|
||||
static inline void M_C(name, _init_move)(M_C(name,_t) el, M_C(name,_t) org) { \
|
||||
M_MAP(TUPLE_DEFINE_INIT_MOVE_FUNC , __VA_ARGS__) \
|
||||
}
|
||||
#define TUPLE_DEFINE_INIT_MOVE_FUNC(a) \
|
||||
TUPLE_GET_INIT_MOVE a (el -> TUPLE_GET_FIELD a, org -> TUPLE_GET_FIELD a);
|
||||
|
||||
#define TUPLE_DEFINE_MOVE(name, ...) \
|
||||
static inline void CAT(name, _move)(CAT(name,_t) el, CAT(name,_t) org) { \
|
||||
static inline void M_C(name, _move)(M_C(name,_t) el, M_C(name,_t) org) { \
|
||||
M_MAP(TUPLE_DEFINE_MOVE_FUNC , __VA_ARGS__) \
|
||||
}
|
||||
#define TUPLE_DEFINE_MOVE_FUNC(a) \
|
||||
@@ -242,14 +242,14 @@
|
||||
M_REDUCE2(TUPLE_TEST_METHOD_P, M_AND, MOVE, __VA_ARGS__)
|
||||
|
||||
#define TUPLEI_OPLIST(name, ...) \
|
||||
(INIT(CAT(name,_init)), \
|
||||
INIT_SET(CAT(name, _init_set)), \
|
||||
SET(CAT(name,_set)), \
|
||||
CLEAR(CAT(name, _clear)), \
|
||||
TYPE(CAT(name,_t)), \
|
||||
M_IF_METHOD_ALL(CMP, __VA_ARGS__)(CMP(CAT(name, _cmp)),), \
|
||||
M_IF_METHOD_ALL(HASH, __VA_ARGS__)(HASH(CAT(name, _hash)),), \
|
||||
M_IF_METHOD_ALL(EQUAL, __VA_ARGS__)(EQUAL(CAT(name, _equal_p)),), \
|
||||
(INIT(M_C(name,_init)), \
|
||||
INIT_SET(M_C(name, _init_set)), \
|
||||
SET(M_C(name,_set)), \
|
||||
CLEAR(M_C(name, _clear)), \
|
||||
TYPE(M_C(name,_t)), \
|
||||
M_IF_METHOD_ALL(CMP, __VA_ARGS__)(CMP(M_C(name, _cmp)),), \
|
||||
M_IF_METHOD_ALL(HASH, __VA_ARGS__)(HASH(M_C(name, _hash)),), \
|
||||
M_IF_METHOD_ALL(EQUAL, __VA_ARGS__)(EQUAL(M_C(name, _equal_p)),), \
|
||||
)
|
||||
|
||||
/********************** External interface *************************/
|
||||
|
||||
+3
-3
@@ -29,9 +29,9 @@ static void test_cat(void)
|
||||
{
|
||||
#define AandB true
|
||||
#define AandBandC true
|
||||
assert (CAT(A,andB));
|
||||
assert (CAT3(A,and,B));
|
||||
assert (CAT4(A,and,B,andC));
|
||||
assert (M_C(A,andB));
|
||||
assert (M_C3(A,and,B));
|
||||
assert (M_C4(A,and,B,andC));
|
||||
}
|
||||
|
||||
static void test_power2(void)
|
||||
|
||||
Reference in new issue
Block a user