Rename _map into _for_each.
This commit is contained in:
1 parent
f962bc8da5
commit
79158dabbc
3 files changed
+18
-17
No files matched your search
@@ -18,5 +18,6 @@ V0.2.*: * worker_sync takes a 'worker_t' as an additional parameter
|
||||
since it only requires one argument.
|
||||
* ALGO _contains ==> _contain_p
|
||||
since it is a predicate '_p' and it shall be in infinitive form.
|
||||
* Rename algo _map into _for_each (Standard name).
|
||||
|
||||
|
||||
@@ -37,11 +37,11 @@
|
||||
|
||||
/* Map a function or a macro to all elements of a container.
|
||||
USAGE:
|
||||
ALGO_MAP(container, containerOplist, function[, extra arguments of function]) */
|
||||
#define ALGO_MAP(container, cont_oplist, ...) \
|
||||
ALGO_FOR_EACH(container, containerOplist, function[, extra arguments of function]) */
|
||||
#define ALGO_FOR_EACH(container, cont_oplist, ...) \
|
||||
M_IF_NARGS_EQ1(__VA_ARGS__) \
|
||||
(ALGOI_MAP(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__), \
|
||||
ALGOI_MAP_ARG(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__ ))
|
||||
(ALGOI_FOR_EACH(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__), \
|
||||
ALGOI_FOR_EACH_ARG(container, M_GLOBAL_OPLIST(cont_oplist), __VA_ARGS__ ))
|
||||
|
||||
|
||||
/* Extract a subset of a container to fill in another container.
|
||||
@@ -63,8 +63,8 @@
|
||||
M_IF_NARGS_EQ1(__VA_ARGS__) \
|
||||
(ALGOI_REDUCE(dest, M_GLOBAL_OPLIST(cont), M_GLOBAL_OPLIST(contOp), __VA_ARGS__), \
|
||||
M_IF_NARGS_EQ2(__VA_ARGS__) \
|
||||
(ALGOI_REDUCE_MAP(dest, M_GLOBAL_OPLIST(cont), M_GLOBAL_OPLIST(contOp), __VA_ARGS__), \
|
||||
ALGOI_REDUCE_MAP_ARG(dest, M_GLOBAL_OPLIST(cont), M_GLOBAL_OPLIST(contOp), __VA_ARGS__) ) )
|
||||
(ALGOI_REDUCE_FOR_EACH(dest, M_GLOBAL_OPLIST(cont), M_GLOBAL_OPLIST(contOp), __VA_ARGS__), \
|
||||
ALGOI_REDUCE_FOR_EACH_ARG(dest, M_GLOBAL_OPLIST(cont), M_GLOBAL_OPLIST(contOp), __VA_ARGS__) ) )
|
||||
|
||||
|
||||
/* Initialize & set a container with a variable array list.
|
||||
@@ -237,7 +237,7 @@
|
||||
} \
|
||||
\
|
||||
static inline void \
|
||||
M_C(name, _map) (container_t l, void (*f)(type_t const) ) \
|
||||
M_C(name, _for_each) (container_t l, void (*f)(type_t) ) \
|
||||
{ \
|
||||
for M_EACH(item, l, cont_oplist) { \
|
||||
f(*item); \
|
||||
@@ -711,15 +711,15 @@
|
||||
|
||||
//TODO: Algorithm missing
|
||||
// nth_element ( http://softwareengineering.stackexchange.com/questions/284767/kth-selection-routine-floyd-algorithm-489 )
|
||||
//, average, find_if, count_if, ...
|
||||
//, average
|
||||
|
||||
#define ALGOI_MAP(container, cont_oplist, func) do { \
|
||||
#define ALGOI_FOR_EACH(container, cont_oplist, func) do { \
|
||||
for M_EACH(item, container, cont_oplist) { \
|
||||
func(*item); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ALGOI_MAP_ARG(container, cont_oplist, func, ...) do { \
|
||||
#define ALGOI_FOR_EACH_ARG(container, cont_oplist, func, ...) do { \
|
||||
for M_EACH(item, container, cont_oplist) { \
|
||||
func(__VA_ARGS__, *item); \
|
||||
} \
|
||||
@@ -786,7 +786,7 @@
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ALGOI_REDUCE_MAP(dest, cont, cont_oplist, reduceFunc, mapFunc) do { \
|
||||
#define ALGOI_REDUCE_FOR_EACH(dest, cont, cont_oplist, reduceFunc, mapFunc) do { \
|
||||
bool m_init_done = false; \
|
||||
M_GET_SUBTYPE cont_oplist m_tmp; \
|
||||
M_GET_INIT M_GET_OPLIST cont_oplist (m_tmp); \
|
||||
@@ -802,7 +802,7 @@
|
||||
M_GET_CLEAR M_GET_OPLIST cont_oplist (m_tmp); \
|
||||
} while (0)
|
||||
|
||||
#define ALGOI_REDUCE_MAP_ARG(dest, cont, cont_oplist, reduceFunc, mapFunc, ...) do { \
|
||||
#define ALGOI_REDUCE_FOR_EACH_ARG(dest, cont, cont_oplist, reduceFunc, mapFunc, ...) do { \
|
||||
bool m_init_done = false; \
|
||||
M_GET_SUBTYPE cont_oplist m_tmp; \
|
||||
M_GET_INIT M_GET_OPLIST cont_oplist (m_tmp); \
|
||||
|
||||
+5
-5
@@ -116,9 +116,9 @@ static void test_list(void)
|
||||
assert (algo_list_none_of_p(l, func_test_pos) == false);
|
||||
|
||||
#define f(x) assert((x) >= 0 && (x) < 100);
|
||||
ALGO_MAP(l, LIST_OPLIST(list_int), f);
|
||||
ALGO_FOR_EACH(l, LIST_OPLIST(list_int), f);
|
||||
#define g(y, x) assert((x) >= 0 && (x) < y);
|
||||
ALGO_MAP(l, LIST_OPLIST(list_int), g, 100);
|
||||
ALGO_FOR_EACH(l, LIST_OPLIST(list_int), g, 100);
|
||||
|
||||
assert( algo_list_count_if(l, func_test_42) == 1);
|
||||
assert( algo_list_count_if(l, func_test_101) == 0);
|
||||
@@ -203,13 +203,13 @@ static void test_array(void)
|
||||
assert (array_int_end_p (it));
|
||||
|
||||
#define f(x) assert((x) >= 0 && (x) < 100);
|
||||
ALGO_MAP(l, ARRAY_OPLIST(array_int), f);
|
||||
ALGO_MAP(l, array_int_t, f);
|
||||
ALGO_FOR_EACH(l, ARRAY_OPLIST(array_int), f);
|
||||
ALGO_FOR_EACH(l, array_int_t, f);
|
||||
|
||||
g_min = 0;
|
||||
g_max = 99;
|
||||
g_count = 0;
|
||||
algo_array_map(l, g_f);
|
||||
algo_array_for_each(l, g_f);
|
||||
assert(g_count == 101);
|
||||
|
||||
int n;
|
||||
|
||||
Reference in new issue
Block a user