Port algo to new memory format

This commit is contained in:
Patrick Pelissier committed 2025-05-07 21:02:24 +02:00
1 parent 93a1be616d
commit 0de3c622e3
3 files changed
+36 -34

No files matched your search

+3 -1
View File
@@ -35,7 +35,7 @@ static void my_free(void *ptr, size_t old, size_t base, context_t context)
#include "m-bitset.h"
#include "m-bstring.h"
#include "m-genint.h"
#include "m-algo.h"
context_t my_pool = NULL;
extern int f(string_t, bitset_t b, bstring_t y);
@@ -59,7 +59,9 @@ int f(string_t x, bitset_t b, bstring_t y)
#include "m-array.h"
ARRAY_DEF(array, int)
ALGO_DEF(array, ARRAY_OPLIST(array, M_BASIC_OPLIST))
ARRAY_DEF(array_str, string_t)
ALGO_DEF(array_str, ARRAY_OPLIST(array_str, STRING_OPLIST))
#include "m-prioqueue.h"
+17 -24
View File
@@ -434,7 +434,7 @@
/* Compute the union of two ***sorted*** containers */ \
M_IF_METHOD(IT_INSERT, cont_oplist)( \
M_INLINE void \
M_C3(name,sort_name,_union)(container_t dst, const container_t src cmp_param(name)) \
M_C3(name,sort_name,_union)(M_P_EXPAND container_t dst, const container_t src cmp_param(name)) \
{ \
it_t itSrc; \
it_t itDst; \
@@ -479,7 +479,7 @@
/* Compute the intersection of two ***sorted*** containers */ \
M_IF_METHOD(IT_REMOVE, cont_oplist)( \
M_INLINE void \
M_C3(name,sort_name,_intersect)(container_t dst, const container_t src cmp_param(name)) \
M_C3(name,sort_name,_intersect)(M_P_EXPAND container_t dst, const container_t src cmp_param(name)) \
{ \
it_t itSrc; \
it_t itDst; \
@@ -688,9 +688,9 @@
#define M_ALG0_DEF_FILL(name, container_t, cont_oplist, type_t, type_oplist, it_t) \
\
/* Fill all the container with value (overwritten) */ \
M_INLINE void \
M_F(name, _fill) (container_t l, type_t const value) \
M_P(void, name, _fill, container_t l, type_t const value) \
{ \
M_UNUSED_CONTEXT(); \
for M_EACH(item, l, cont_oplist) { \
M_CALL_SET(type_oplist, *item, value); \
} \
@@ -698,8 +698,7 @@
\
/* Fill the container with exactly 'n' occurrence of 'value' */ \
M_IF_METHOD(PUSH, cont_oplist)( \
M_INLINE void \
M_F(name, _fill_n) (container_t l, size_t n, type_t const value) \
M_P(void, name, _fill_n, container_t l, size_t n, type_t const value) \
{ \
M_CALL_RESET(cont_oplist, l); \
for(size_t i = 0; i < n; i++) { \
@@ -710,9 +709,9 @@
\
/* Fill the container with FOR('value'; 'value'+'inc') */ \
M_IF_METHOD(ADD, type_oplist)( \
M_INLINE void \
M_F(name, _fill_a) (container_t l, type_t const value, type_t const inc) \
M_P(void, name, _fill_a, container_t l, type_t const value, type_t const inc) \
{ \
M_UNUSED_CONTEXT(); \
type_t tmp; \
M_CALL_INIT_SET(type_oplist, tmp, value); \
for M_EACH(item, l, cont_oplist) { \
@@ -724,9 +723,9 @@
\
/* Fill the container with n occurences of FOR('value'; 'value'+'inc') */ \
M_IF_METHOD(PUSH, cont_oplist)( \
M_INLINE void \
M_F(name, _fill_an) (container_t l, size_t n, type_t const value, type_t const inc) \
M_P(void, name, _fill_an, container_t l, size_t n, type_t const value, type_t const inc) \
{ \
M_UNUSED_CONTEXT(); \
type_t tmp; \
M_CALL_INIT_SET(type_oplist, tmp, value); \
M_CALL_RESET(cont_oplist, l); \
@@ -756,10 +755,7 @@
M_IF_METHOD(PUSH_MOVE, cont_oplist)( \
\
/* Apply func for all elements of the container src and push the result in dst */ \
M_INLINE void \
M_F(name, _transform) (container_t dst, \
container_t src, \
M_F(name, _transform_cb_ct) func) \
M_P(void, name, _transform, container_t dst, container_t src, M_F(name, _transform_cb_ct) func) \
{ \
M_ASSERT(dst != src); \
M_CALL_RESET(cont_oplist, dst); \
@@ -775,10 +771,10 @@
\
/* Reduce all elements of the container in dst in function of func */ \
M_IF_METHOD(SET, type_oplist)( \
M_INLINE void \
M_F(name, _reduce) (type_t *dest, container_t const l, \
M_P(void, name, _reduce, type_t *dest, container_t const l, \
M_F(name, _transform_cb_ct) func) \
{ \
M_UNUSED_CONTEXT(); \
bool initDone = false; \
for M_EACH(item, l, cont_oplist) { \
if (initDone) { \
@@ -793,12 +789,12 @@
\
/* Reduce all transformed elements of the container in dst in function of func */ \
M_IF_METHOD(INIT, type_oplist)( \
M_INLINE \
void M_F(name, _map_reduce) (type_t *dest, \
M_P(void, name, _map_reduce, type_t *dest, \
const container_t l, \
M_F(name, _transform_cb_ct) redFunc, \
M_F(name, _transform_cb_ct) mapFunc) \
{ \
M_UNUSED_CONTEXT(); \
bool initDone = false; \
type_t tmp; \
M_CALL_INIT(type_oplist, tmp); \
@@ -905,8 +901,7 @@
/* Define functions based on remove method */
#define M_ALG0_DEF_REMOVE(name, container_t, cont_oplist, type_t, type_oplist, it_t) \
\
M_INLINE void \
M_F(name, _uniq)(container_t l) \
M_P(void, name, _uniq, container_t l) \
{ \
it_t it1; \
it_t it2; \
@@ -927,8 +922,7 @@
} \
} \
\
M_INLINE void \
M_F(name, _remove_val)(container_t l, type_t const val) \
M_P(void, name, _remove_val, container_t l, type_t const val) \
{ \
it_t it1; \
M_CALL_IT_FIRST(cont_oplist, it1, l); \
@@ -942,8 +936,7 @@
} \
} \
\
M_INLINE void \
M_F(name, _remove_if)(container_t l, M_F(name, _test_cb_ct) func) \
M_P(void, name, _remove_if, container_t l, M_F(name, _test_cb_ct) func) \
{ \
it_t it1; \
M_CALL_IT_FIRST(cont_oplist, it1, l); \
+16 -9
View File
@@ -2018,8 +2018,7 @@ m_string_utf8_p(const m_string_t str)
/* Define the split & the join functions
in case of usage with the algorithm module */
#define M_STR1NG_SPLIT(name, oplist, type_oplist) \
M_INLINE void M_F(name, _split)(M_GET_TYPE oplist cont, \
const m_string_t str, const char sep) \
M_P(void, name, _split, M_GET_TYPE oplist cont, const m_string_t str, const char sep) \
{ \
size_t begin = 0; \
m_string_t tmp; \
@@ -2029,7 +2028,7 @@ m_string_utf8_p(const m_string_t str)
for(size_t i = 0 ; i < size; i++) { \
char c = m_string_get_char(str, i); \
if (c == sep) { \
m_string_set_cstrn(tmp, &m_string_get_cstr(str)[begin], i - begin); \
m_string_set_cstrn M_R(tmp, &m_string_get_cstr(str)[begin], i - begin); \
/* If push move method is available, use it */ \
M_IF_METHOD(PUSH_MOVE,oplist)( \
M_CALL_PUSH_MOVE(oplist, cont, &tmp); \
@@ -2040,24 +2039,23 @@ m_string_utf8_p(const m_string_t str)
begin = i + 1; \
} \
} \
m_string_set_cstrn(tmp, &m_string_get_cstr(str)[begin], size - begin); \
m_string_set_cstrn M_R(tmp, &m_string_get_cstr(str)[begin], size - begin); \
M_CALL_PUSH(oplist, cont, tmp); \
/* HACK: if method reverse is defined, it is likely that we have */ \
/* inserted the items in the wrong order (aka for a list) */ \
M_IF_METHOD(REVERSE, oplist) (M_CALL_REVERSE(oplist, cont);, ) \
m_string_clear(tmp); \
m_string_clear M_R(tmp); \
} \
\
M_INLINE void M_F(name, _join)(m_string_t dst, M_GET_TYPE oplist cont, \
const m_string_t str) \
M_P(void, name, _join, m_string_t dst, M_GET_TYPE oplist cont, const m_string_t str) \
{ \
bool init_done = false; \
m_string_reset (dst); \
for M_EACH(item, cont, oplist) { \
if (init_done) { \
m_string_cat(dst, str); \
m_string_cat M_R(dst, str); \
} \
m_string_cat (dst, *item); \
m_string_cat M_R(dst, *item); \
init_done = true; \
} \
} \
@@ -2287,7 +2285,16 @@ namespace m_lib {
#endif
/* Concatenate the string (or C string) b to the string a */
#ifdef M_USE_CONTEXT
#define m_string_cat(p, a,b) \
_Generic((b)+0, \
char*: m_string_cat_cstr, \
const char *: m_string_cat_cstr, \
default : m_string_cat \
)(p,a,b)
#else
#define m_string_cat(a,b) M_STR1NG_SELECT2(m_string_cat, m_string_cat_cstr, a, b)
#endif
/* Compare the string a to the string (or C string) b and return the sort order */
#define m_string_cmp(a,b) M_STR1NG_SELECT2(m_string_cmp, m_string_cmp_cstr, a, b)