Add new macros to define container

with the full given name.
This commit is contained in:
Patrick Pelissier committed 2020-10-03 14:07:14 +02:00
1 parent 1d8e541205
commit 7f26ef0f1c
6 files changed
+96 -2

No files matched your search

+11
View File
@@ -56,6 +56,17 @@ M_BEGIN_PROTECTED_CODE
M_END_PROTECTED_CODE
/* Define the intrusive shared pointer type and its static inline functions
as the name name_t
USAGE: ISHARED_PTR_DEF_AS(name, name_t, type, [, oplist]) */
#define ISHARED_PTR_DEF_AS(name, name_t, ...) \
M_BEGIN_PROTECTED_CODE \
ISHAREDI_PTR_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t ), \
(name, __VA_ARGS__ , name_t ))) \
M_END_PROTECTED_CODE
/********************************** INTERNAL ************************************/
// Deferred evaluation
+1 -1
View File
@@ -49,7 +49,7 @@
/* Define a singly linked list of a given type allowing both push.
USAGE: LIST_DUAL_PUSH_DEF(name, type [, oplist_of_the_type]) */
USAGE: LIST_DUAL_PUSH_DEF_AS(name, name_t, type [, oplist_of_the_type]) */
#define LIST_DUAL_PUSH_DEF(name, ...) \
M_BEGIN_PROTECTED_CODE \
LISTI_DUAL_PUSH_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
+10
View File
@@ -45,6 +45,16 @@
M_END_PROTECTED_CODE
/* Fast Fixed Size thread unsafe allocator based on memory region.
USAGE:
MEMPOOL_DEF_AS(memppol_uint, name_t, unsigned int)
*/
#define MEMPOOL_DEF_AS(name, name_t, type) \
M_BEGIN_PROTECTED_CODE \
MEMPOOL_DEF_P2(name, type, name_t ) \
M_END_PROTECTED_CODE
/* User shall be able to cutomize the size of the segment and/or
the minimun number of elements.
The default is the number of elements that fits in 16KB.
+21 -1
View File
@@ -40,6 +40,17 @@
M_END_PROTECTED_CODE
/* Define a prioqueue of a given type and its associated functions.
as the name name_t with an iterator named it_t
USAGE: PRIOQUEUE_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */
#define PRIOQUEUE_DEF_AS(name, name_t, it_t, ...) \
M_BEGIN_PROTECTED_CODE \
PRIOQUEUEI_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, it_t ), \
(name, __VA_ARGS__, name_t, it_t ))) \
M_END_PROTECTED_CODE
/* Define the oplist of a prioqueue of type.
USAGE: PRIOQUEUE_OPLIST(name[, oplist of the type]) */
#define PRIOQUEUE_OPLIST(...) \
@@ -81,6 +92,15 @@
,OPLIST(oplist) \
,TEST_EMPTY(M_C(name, _empty_p)), \
,GET_SIZE(M_C(name, _size)) \
,IT_TYPE(M_C(name, _it_ct)), \
IT_FIRST(M_C(name,_it)), \
IT_END(M_C(name,_it_end)), \
IT_SET(M_C(name,_it_set)), \
IT_END_P(M_C(name,_end_p)), \
IT_EQUAL_P(M_C(name,_it_equal_p)), \
IT_LAST_P(M_C(name,_last_p)), \
IT_NEXT(M_C(name,_next)), \
IT_CREF(M_C(name,_cref)), \
)
@@ -122,7 +142,7 @@
/* Definition of the internal types used by the oplist */ \
typedef prioqueue_t M_C(name, _ct); \
typedef type M_C(name, _subtype_ct); \
typedef it_t M_C(name, _subtype_t); \
typedef it_t M_C(name, _it_ct); \
\
M_CHECK_COMPATIBLE_OPLIST(name, 1, type, oplist) \
\
+37
View File
@@ -31,6 +31,8 @@ START_COVERAGE
MEMPOOL_DEF(mempool_uint, unsigned int)
END_COVERAGE
MEMPOOL_DEF_AS(MempoolDouble, MempoolDouble, unsigned int)
static void test(void)
{
mempool_uint_t m;
@@ -65,8 +67,43 @@ static void test(void)
mempool_uint_clear(m);
}
static void test_double(void)
{
MempoolDouble m;
MempoolDouble_init(m);
unsigned int *tab[100000];
for(unsigned int i = 0; i < 100000; i++) {
tab[i] = MempoolDouble_alloc(m);
*tab[i] = i;
}
for(unsigned int i = 0; i < 100000; i++) {
assert (*tab[i] == i);
}
for(unsigned int i = 0; i < 100000; i+=2) {
MempoolDouble_free(m, tab[i]);
tab[i] = NULL;
}
for(unsigned int i = 1; i < 100000; i+=2) {
assert (*tab[i] == i);
}
for(unsigned int i = 0; i < 100000; i+=2) {
tab[i] = MempoolDouble_alloc(m);
*tab[i] = i;
}
for(unsigned int i = 0; i < 100000; i++) {
assert (*tab[i] == i);
}
for(unsigned int i = 0; i < 100000; i++) {
MempoolDouble_free(m, tab[i]);
tab[i] = NULL;
}
MempoolDouble_clear(m);
}
int main(void)
{
test();
test_double();
exit(0);
}
+16
View File
@@ -31,6 +31,9 @@ PRIOQUEUE_DEF(int_pqueue, int)
END_COVERAGE
PRIOQUEUE_DEF(mpz_pqueue, testobj_t, TESTOBJ_CMP_OPLIST)
PRIOQUEUE_DEF_AS(PrioDouble, PrioDouble, PrioDoubleIt, double)
#define M_OPL_PrioDouble() PRIOQUEUE_OPLIST(PrioDouble, M_DEFAULT_OPLIST)
static void test1(void)
{
int x;
@@ -101,9 +104,22 @@ static void test2(void)
int_pqueue_clear(p);
}
static void test_double(void)
{
M_LET( (tab, 0.0, 1.0, 2.0, 3.0), PrioDouble) {
double ref = 0.0;
// NOTE: The binary heap is sorted in the same natural order that the sorted array
for M_EACH(i, tab, PrioDouble) {
assert (*i == ref);
ref += 1.0;
}
}
}
int main(void)
{
test1();
test2();
test_double();
exit(0);
}