Add ALGO_REDUCE macro

This commit is contained in:
Patrick Pelissier committed 2017-03-03 21:30:38 +01:00
1 parent 2af4cb2fc2
commit 85596c1a7a
2 files changed
+75 -10

No files matched your search

+12
View File
@@ -87,6 +87,18 @@ static void test_extract(void)
#define cond2(c, d) ((d) > (c))
ALGO_EXTRACT(a, ARRAY_OPLIST(int), l, LIST_OPLIST(int), cond2, 10);
assert(array_int_size(a) == 89);
int dst = 0;
#define inc(d, c) (d) += (c)
ALGO_REDUCE(dst, a, ARRAY_OPLIST(int), inc);
assert (dst == 100*99/2-10*11/2);
#define sqr(d, c) (d) = (c)*(c)
ALGO_REDUCE(dst, a, ARRAY_OPLIST(int), inc, sqr);
assert (dst == 327965);
#define sqr2(d, f, c) (d) = (f) * (c)
ALGO_REDUCE(dst, a, ARRAY_OPLIST(int), inc, sqr2, 4);
assert (dst == (100*99/2-10*11/2) *4 );
array_int_clear(a);
list_int_clear(l);
}