Add macro RBTREE_DEF_AS
This commit is contained in:
1 parent
7f26ef0f1c
commit
acb886c391
2 files changed
+26
-1
No files matched your search
+11
@@ -39,6 +39,17 @@
|
||||
M_END_PROTECTED_CODE
|
||||
|
||||
|
||||
/* Define a Red/Black binary tree of a given type
|
||||
as the name name_t and the iterator it_t.
|
||||
USAGE: RBTREE_DEF_AS(name, name_t, it_t, type [, oplist_of_the_type]) */
|
||||
#define RBTREE_DEF_AS(name, name_t, it_t, ...) \
|
||||
M_BEGIN_PROTECTED_CODE \
|
||||
RBTREEI_DEF_P1(M_IF_NARGS_EQ1(__VA_ARGS__) \
|
||||
((name, __VA_ARGS__, M_GLOBAL_OPLIST_OR_DEF(__VA_ARGS__)(), name_t, M_C(name, _node_ct), it_t ), \
|
||||
(name, __VA_ARGS__, name_t, M_C(name, _node_ct), it_t ))) \
|
||||
M_END_PROTECTED_CODE
|
||||
|
||||
|
||||
/* Define the oplist of a rbtree of type.
|
||||
USAGE: RBTREE_OPLIST(name [, oplist_of_the_type]) */
|
||||
#define RBTREE_OPLIST(...) \
|
||||
|
||||
+15
-1
@@ -60,6 +60,9 @@ RBTREE_DEF(rbtree_mpz, testobj_t, TESTOBJ_OPLIST)
|
||||
#define UINT_OPLIST RBTREE_OPLIST(rbtree_uint)
|
||||
#define FLOAT_OP RBTREE_OPLIST(rbtree_float)
|
||||
|
||||
RBTREE_DEF_AS(TreeDouble, TreeDouble, TreeDoubleIt, double, M_DEFAULT_OPLIST)
|
||||
#define M_OPL_TreeDouble() RBTREE_OPLIST(TreeDouble, M_DEFAULT_OPLIST)
|
||||
|
||||
static void test_uint(void)
|
||||
{
|
||||
rbtree_uint_t tree, tree2, tree3;
|
||||
@@ -257,8 +260,18 @@ static void test_io(void)
|
||||
assert(b);
|
||||
assert(*sp == 0);
|
||||
assert(rbtree_uint_equal_p(tree1, tree2));
|
||||
}
|
||||
}
|
||||
|
||||
static void test_double(void)
|
||||
{
|
||||
M_LET( (tree, 0.0, 1.0, 2.0), TreeDouble) {
|
||||
double ref = 0.0;
|
||||
for M_EACH(i, tree, TreeDouble) {
|
||||
assert (*i == ref);
|
||||
ref += 1.0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@@ -267,5 +280,6 @@ int main(void)
|
||||
test_uint_permut();
|
||||
test_float();
|
||||
test_io();
|
||||
test_double();
|
||||
exit(0);
|
||||
}
|
||||
Reference in new issue
Block a user