Port to M_CALL for R/B TREE.
This commit is contained in:
1 parent
fd3453bb2a
commit
74c12e6ea2
2 files changed
+30
-30
No files matched your search
+5
-5
@@ -152,8 +152,8 @@
|
|||||||
static inline int \
|
static inline int \
|
||||||
M_C(name, _i_cmp)(const prioqueue_t p, size_t i, size_t j) \
|
M_C(name, _i_cmp)(const prioqueue_t p, size_t i, size_t j) \
|
||||||
{ \
|
{ \
|
||||||
return M_GET_CMP oplist (*M_C(name, _array_cget)(p->array, i), \
|
return M_CALL_CMP(oplist, *M_C(name, _array_cget)(p->array, i), \
|
||||||
*M_C(name, _array_cget)(p->array, j)); \
|
*M_C(name, _array_cget)(p->array, j)); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline bool \
|
static inline bool \
|
||||||
@@ -282,7 +282,7 @@
|
|||||||
size_t size = M_C(name, _array_size)(p->array); \
|
size_t size = M_C(name, _array_size)(p->array); \
|
||||||
size_t i = 0; \
|
size_t i = 0; \
|
||||||
for(i = 0; i < size; i++) { \
|
for(i = 0; i < size; i++) { \
|
||||||
if (M_GET_EQUAL oplist (*M_C(name, _array_cget)(p->array, i), x)) \
|
if (M_CALL_EQUAL(oplist, *M_C(name, _array_cget)(p->array, i), x)) \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
/* If x is not found, then stop */ \
|
/* If x is not found, then stop */ \
|
||||||
@@ -311,12 +311,12 @@
|
|||||||
M_C(name, _update_further)(prioqueue_t p, type xold, type xnew) \
|
M_C(name, _update_further)(prioqueue_t p, type xold, type xnew) \
|
||||||
{ \
|
{ \
|
||||||
/* This update assumes that the new position is further in the heap */ \
|
/* This update assumes that the new position is further in the heap */ \
|
||||||
assert (M_GET_CMP oplist (xold, xnew) > 0); \
|
assert (M_CALL_CMP(oplist, xold, xnew) > 0); \
|
||||||
/* First pass: search for an item EQUAL to x */ \
|
/* First pass: search for an item EQUAL to x */ \
|
||||||
size_t size = M_C(name, _array_size)(p->array); \
|
size_t size = M_C(name, _array_size)(p->array); \
|
||||||
size_t i = 0; \
|
size_t i = 0; \
|
||||||
for(i = 0; i < size; i++) { \
|
for(i = 0; i < size; i++) { \
|
||||||
if (M_GET_EQUAL oplist (*M_C(name, _array_cget)(p->array, i), xold)) \
|
if (M_CALL_EQUAL(oplist, *M_C(name, _array_cget)(p->array, i), xold)) \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
/* We shall have found the item */ \
|
/* We shall have found the item */ \
|
||||||
|
|||||||
+25
-25
@@ -165,10 +165,10 @@ typedef enum {
|
|||||||
, /* No mempool allocation */ \
|
, /* No mempool allocation */ \
|
||||||
\
|
\
|
||||||
static inline node_t *M_C(name,_int_new)(void) { \
|
static inline node_t *M_C(name,_int_new)(void) { \
|
||||||
return M_GET_NEW oplist (node_t); \
|
return M_CALL_NEW(oplist, node_t); \
|
||||||
} \
|
} \
|
||||||
static inline void M_C(name,_int_del)(node_t *ptr) { \
|
static inline void M_C(name,_int_del)(node_t *ptr) { \
|
||||||
M_GET_DEL oplist (ptr); \
|
M_CALL_DEL(oplist, ptr); \
|
||||||
} ) \
|
} ) \
|
||||||
\
|
\
|
||||||
RBTREEI_DEF3(name, type, oplist, tree_t, node_t, tree_it_t)
|
RBTREEI_DEF3(name, type, oplist, tree_t, node_t, tree_it_t)
|
||||||
@@ -210,7 +210,7 @@ typedef enum {
|
|||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
assert (n == stack[cpt - 1]); \
|
assert (n == stack[cpt - 1]); \
|
||||||
M_GET_CLEAR oplist (n->data); \
|
M_CALL_CLEAR(oplist, n->data); \
|
||||||
M_C(name,_int_del) (n); \
|
M_C(name,_int_del) (n); \
|
||||||
assert((stack[cpt-1] = NULL) == NULL); \
|
assert((stack[cpt-1] = NULL) == NULL); \
|
||||||
cpt--; \
|
cpt--; \
|
||||||
@@ -240,7 +240,7 @@ typedef enum {
|
|||||||
M_MEMORY_FULL(sizeof (node_t)); \
|
M_MEMORY_FULL(sizeof (node_t)); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
M_GET_INIT_SET oplist (n->data, data); \
|
M_CALL_INIT_SET(oplist, n->data, data); \
|
||||||
n->child[0] = n->child[1] = NULL; \
|
n->child[0] = n->child[1] = NULL; \
|
||||||
RBTREEI_SET_BLACK (n); \
|
RBTREEI_SET_BLACK (n); \
|
||||||
tree->node = n; \
|
tree->node = n; \
|
||||||
@@ -253,7 +253,7 @@ typedef enum {
|
|||||||
tab[cpt] = n; \
|
tab[cpt] = n; \
|
||||||
while (n != NULL) { \
|
while (n != NULL) { \
|
||||||
RBTREEI_CONTRACT_NODE(n); \
|
RBTREEI_CONTRACT_NODE(n); \
|
||||||
int cmp = M_GET_CMP oplist (n->data, data); \
|
int cmp = M_CALL_CMP(oplist, n->data, data); \
|
||||||
if (cmp == 0) { \
|
if (cmp == 0) { \
|
||||||
break; \
|
break; \
|
||||||
} else if (cmp > 0) { \
|
} else if (cmp > 0) { \
|
||||||
@@ -268,8 +268,8 @@ typedef enum {
|
|||||||
} \
|
} \
|
||||||
/* If found, update the data (default is set) */ \
|
/* If found, update the data (default is set) */ \
|
||||||
if (n != NULL) { \
|
if (n != NULL) { \
|
||||||
M_IF_METHOD (UPDATE, oplist)(M_GET_UPDATE oplist, M_GET_SET oplist) \
|
M_IF_METHOD (UPDATE, oplist)(M_CALL_UPDATE(oplist, n->data, data) \
|
||||||
(n->data, data); \
|
, M_CALL_SET(oplist, n->data, data)); \
|
||||||
RBTREEI_CONTRACT (tree); \
|
RBTREEI_CONTRACT (tree); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
@@ -279,7 +279,7 @@ typedef enum {
|
|||||||
M_MEMORY_FULL (sizeof (node_t)); \
|
M_MEMORY_FULL (sizeof (node_t)); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
M_GET_INIT_SET oplist (n->data, data); \
|
M_CALL_INIT_SET(oplist, n->data, data); \
|
||||||
n->child[0] = n->child[1] = NULL; \
|
n->child[0] = n->child[1] = NULL; \
|
||||||
RBTREEI_SET_RED (n); \
|
RBTREEI_SET_RED (n); \
|
||||||
assert (tab[cpt] == NULL); \
|
assert (tab[cpt] == NULL); \
|
||||||
@@ -485,7 +485,7 @@ typedef enum {
|
|||||||
node_t *n = tree->node; \
|
node_t *n = tree->node; \
|
||||||
it->stack[cpt] = n; \
|
it->stack[cpt] = n; \
|
||||||
while (n != NULL) { \
|
while (n != NULL) { \
|
||||||
int cmp = M_GET_CMP oplist (n->data, data); \
|
int cmp = M_CALL_CMP(oplist, n->data, data); \
|
||||||
if (cmp == 0) \
|
if (cmp == 0) \
|
||||||
break; \
|
break; \
|
||||||
int child = (cmp < 0); \
|
int child = (cmp < 0); \
|
||||||
@@ -504,7 +504,7 @@ typedef enum {
|
|||||||
if (it->cpt == 0) return true; \
|
if (it->cpt == 0) return true; \
|
||||||
assert (it->cpt > 0 && it->cpt < RBTREEI_MAX_STACK); \
|
assert (it->cpt > 0 && it->cpt < RBTREEI_MAX_STACK); \
|
||||||
node_t *n = it->stack[it->cpt-1]; \
|
node_t *n = it->stack[it->cpt-1]; \
|
||||||
int cmp = M_GET_CMP oplist (n->data, data); \
|
int cmp = M_CALL_CMP(oplist, n->data, data); \
|
||||||
return (cmp >= 0); \
|
return (cmp >= 0); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
@@ -553,7 +553,7 @@ typedef enum {
|
|||||||
node_t *n = tree->node; \
|
node_t *n = tree->node; \
|
||||||
while (n != NULL) { \
|
while (n != NULL) { \
|
||||||
RBTREEI_CONTRACT_NODE (n); \
|
RBTREEI_CONTRACT_NODE (n); \
|
||||||
int cmp = M_GET_CMP oplist (n->data, data); \
|
int cmp = M_CALL_CMP(oplist, n->data, data); \
|
||||||
if (cmp == 0) { \
|
if (cmp == 0) { \
|
||||||
return &n->data; \
|
return &n->data; \
|
||||||
} else if (cmp > 0) { \
|
} else if (cmp > 0) { \
|
||||||
@@ -580,7 +580,7 @@ typedef enum {
|
|||||||
M_MEMORY_FULL (sizeof (node_t)); \
|
M_MEMORY_FULL (sizeof (node_t)); \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
} \
|
} \
|
||||||
M_GET_INIT_SET oplist (n->data, o->data); \
|
M_CALL_INIT_SET(oplist, n->data, o->data); \
|
||||||
n->child[0] = M_C(name, _int_copyn)(o->child[0]); \
|
n->child[0] = M_C(name, _int_copyn)(o->child[0]); \
|
||||||
n->child[1] = M_C(name, _int_copyn)(o->child[1]); \
|
n->child[1] = M_C(name, _int_copyn)(o->child[1]); \
|
||||||
RBTREEI_COPY_COLOR (n, o); \
|
RBTREEI_COPY_COLOR (n, o); \
|
||||||
@@ -702,7 +702,7 @@ typedef enum {
|
|||||||
RBTREEI_CONTRACT_NODE (n); \
|
RBTREEI_CONTRACT_NODE (n); \
|
||||||
assert(M_C(name, _int_depth)(n->child[0]) \
|
assert(M_C(name, _int_depth)(n->child[0]) \
|
||||||
== M_C(name, _int_depth)(n->child[1])); \
|
== M_C(name, _int_depth)(n->child[1])); \
|
||||||
int cmp = M_GET_CMP oplist (n->data, key); \
|
int cmp = M_CALL_CMP(oplist, n->data, key); \
|
||||||
if (cmp == 0) { \
|
if (cmp == 0) { \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
@@ -834,8 +834,8 @@ typedef enum {
|
|||||||
assert (tree->node == NULL || RBTREEI_IS_BLACK(tree->node)); \
|
assert (tree->node == NULL || RBTREEI_IS_BLACK(tree->node)); \
|
||||||
/* delete it */ \
|
/* delete it */ \
|
||||||
if (data_ptr != NULL) \
|
if (data_ptr != NULL) \
|
||||||
M_GET_SET oplist (*data_ptr, n->data); \
|
M_CALL_SET(oplist, *data_ptr, n->data); \
|
||||||
M_GET_CLEAR oplist (n->data); \
|
M_CALL_CLEAR(oplist, n->data); \
|
||||||
M_C(name,_int_del) (n); \
|
M_C(name,_int_del) (n); \
|
||||||
tree->size --; \
|
tree->size --; \
|
||||||
RBTREEI_CONTRACT (tree); \
|
RBTREEI_CONTRACT (tree); \
|
||||||
@@ -859,7 +859,7 @@ typedef enum {
|
|||||||
&& !M_C(name, _end_p)(it2)) { \
|
&& !M_C(name, _end_p)(it2)) { \
|
||||||
type const *ref1 = M_C(name, _cref)(it1); \
|
type const *ref1 = M_C(name, _cref)(it1); \
|
||||||
type const *ref2 = M_C(name, _cref)(it2); \
|
type const *ref2 = M_C(name, _cref)(it2); \
|
||||||
if (M_GET_EQUAL oplist (*ref1, *ref2) == false) \
|
if (M_CALL_EQUAL(oplist, *ref1, *ref2) == false) \
|
||||||
return false; \
|
return false; \
|
||||||
M_C(name, _next)(it1); \
|
M_C(name, _next)(it1); \
|
||||||
M_C(name, _next)(it2); \
|
M_C(name, _next)(it2); \
|
||||||
@@ -879,7 +879,7 @@ typedef enum {
|
|||||||
M_C(name, _it)(it1, t1); \
|
M_C(name, _it)(it1, t1); \
|
||||||
while (!M_C(name, _end_p)(it1)) { \
|
while (!M_C(name, _end_p)(it1)) { \
|
||||||
type const *ref1 = M_C(name, _cref)(it1); \
|
type const *ref1 = M_C(name, _cref)(it1); \
|
||||||
M_HASH_UP(hash, M_GET_HASH oplist (*ref1)); \
|
M_HASH_UP(hash, M_CALL_HASH(oplist, *ref1)); \
|
||||||
M_C(name, _next)(it1); \
|
M_C(name, _next)(it1); \
|
||||||
} \
|
} \
|
||||||
return M_HASH_FINAL (hash); \
|
return M_HASH_FINAL (hash); \
|
||||||
@@ -901,7 +901,7 @@ typedef enum {
|
|||||||
string_push_back (str, M_GET_SEPARATOR oplist); \
|
string_push_back (str, M_GET_SEPARATOR oplist); \
|
||||||
commaToPrint = true; \
|
commaToPrint = true; \
|
||||||
type const *ref1 = M_C(name, _cref)(it1); \
|
type const *ref1 = M_C(name, _cref)(it1); \
|
||||||
M_GET_GET_STR oplist(str, *ref1, true); \
|
M_CALL_GET_STR(oplist, str, *ref1, true); \
|
||||||
M_C(name, _next)(it1); \
|
M_C(name, _next)(it1); \
|
||||||
} \
|
} \
|
||||||
string_push_back (str, ']'); \
|
string_push_back (str, ']'); \
|
||||||
@@ -924,7 +924,7 @@ typedef enum {
|
|||||||
fputc (M_GET_SEPARATOR oplist, file); \
|
fputc (M_GET_SEPARATOR oplist, file); \
|
||||||
commaToPrint = true; \
|
commaToPrint = true; \
|
||||||
type const *item = M_C(name, _cref)(it); \
|
type const *item = M_C(name, _cref)(it); \
|
||||||
M_GET_OUT_STR oplist (file, *item); \
|
M_CALL_OUT_STR(oplist, file, *item); \
|
||||||
} \
|
} \
|
||||||
fputc (']', file); \
|
fputc (']', file); \
|
||||||
} \
|
} \
|
||||||
@@ -945,14 +945,14 @@ typedef enum {
|
|||||||
if (M_UNLIKELY (c == 0)) goto exit; \
|
if (M_UNLIKELY (c == 0)) goto exit; \
|
||||||
str--; \
|
str--; \
|
||||||
type item; \
|
type item; \
|
||||||
M_GET_INIT oplist (item); \
|
M_CALL_INIT(oplist, item); \
|
||||||
do { \
|
do { \
|
||||||
bool b = M_GET_PARSE_STR oplist (item, str, &str); \
|
bool b = M_CALL_PARSE_STR(oplist, item, str, &str); \
|
||||||
do { c = *str++; } while (isspace(c)); \
|
do { c = *str++; } while (isspace(c)); \
|
||||||
if (b == false || c == 0) goto exit; \
|
if (b == false || c == 0) goto exit; \
|
||||||
M_C(name, _push)(rbtree, item); \
|
M_C(name, _push)(rbtree, item); \
|
||||||
} while (c == M_GET_SEPARATOR oplist); \
|
} while (c == M_GET_SEPARATOR oplist); \
|
||||||
M_GET_CLEAR oplist (item); \
|
M_CALL_CLEAR(oplist, item); \
|
||||||
success = (c == ']'); \
|
success = (c == ']'); \
|
||||||
exit: \
|
exit: \
|
||||||
if (endp) *endp = str; \
|
if (endp) *endp = str; \
|
||||||
@@ -974,14 +974,14 @@ typedef enum {
|
|||||||
if (M_UNLIKELY (c == EOF)) return false; \
|
if (M_UNLIKELY (c == EOF)) return false; \
|
||||||
ungetc(c, file); \
|
ungetc(c, file); \
|
||||||
type item; \
|
type item; \
|
||||||
M_GET_INIT oplist (item); \
|
M_CALL_INIT(oplist, item); \
|
||||||
do { \
|
do { \
|
||||||
bool b = M_GET_IN_STR oplist (item, file); \
|
bool b = M_CALL_IN_STR(oplist, item, file); \
|
||||||
do { c = fgetc(file); } while (isspace(c)); \
|
do { c = fgetc(file); } while (isspace(c)); \
|
||||||
if (b == false || c == EOF) break; \
|
if (b == false || c == EOF) break; \
|
||||||
M_C(name, _push)(rbtree, item); \
|
M_C(name, _push)(rbtree, item); \
|
||||||
} while (c == M_GET_SEPARATOR oplist); \
|
} while (c == M_GET_SEPARATOR oplist); \
|
||||||
M_GET_CLEAR oplist (item); \
|
M_CALL_CLEAR(oplist, item); \
|
||||||
return c == ']'; \
|
return c == ']'; \
|
||||||
} \
|
} \
|
||||||
, /* no in_str */ ) \
|
, /* no in_str */ ) \
|
||||||
|
|||||||
Reference in new issue
Block a user