Create _raw methods for insertions.

This commit is contained in:
Patrick Pelissier committed 2022-08-01 22:13:41 +02:00
1 parent 65b49268d3
commit c5bb84013a
1 file changed
+45 -10
+45 -10
View File
@@ -423,7 +423,7 @@ typedef int32_t m_tr33_index_t;
} \
\
static inline it_t \
M_C(name, _insert_up)(it_t it, type const data) { \
M_C(name, _insert_up_raw)(it_t it) { \
M_TR33_IT_CONTRACT(it, true); \
m_tr33_index_t i = M_C3(m_tr33_, name, _alloc_node)(it.tree); \
m_tr33_index_t parent = it.tree->tab[it.index].parent; \
@@ -447,13 +447,20 @@ typedef int32_t m_tr33_index_t;
if (right != M_TR33_NO_NODE) { it.tree->tab[right].left = i; } \
/* Return updated iterator on the inserted node */ \
it.index = i; \
M_CALL_INIT_SET(oplist, it.tree->tab[i].data, data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \
\
static inline it_t \
M_C(name, _insert_down)(it_t it, type const data) { \
M_C(name, _insert_up)(it_t pos, type const data) { \
it_t it = M_C(name, _insert_up_raw)(pos); \
M_CALL_INIT_SET(oplist, it.tree->tab[it.index].data, data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \
\
static inline it_t \
M_C(name, _insert_down_raw)(it_t it) { \
M_TR33_IT_CONTRACT(it, true); \
m_tr33_index_t i = M_C3(m_tr33_, name, _alloc_node)(it.tree); \
m_tr33_index_t child = it.tree->tab[it.index].child; \
@@ -469,13 +476,20 @@ typedef int32_t m_tr33_index_t;
} \
/* Return updated iterator on the inserted node */ \
it.index = i; \
M_CALL_INIT_SET(oplist, it.tree->tab[i].data, data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \
\
static inline it_t \
M_C(name, _insert_child)(it_t it, type const data) { \
M_C(name, _insert_down)(it_t pos, type const data) { \
it_t it = M_C(name, _insert_down_raw)(pos); \
M_CALL_INIT_SET(oplist, it.tree->tab[it.index].data, data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \
\
static inline it_t \
M_C(name, _insert_child_raw)(it_t it) { \
M_TR33_IT_CONTRACT(it, true); \
/* Insert a node as a child of another, making the current childreen \
of the nodes their siblings */ \
@@ -493,13 +507,20 @@ typedef int32_t m_tr33_index_t;
} \
/* Return updated iterator on the inserted node */ \
it.index = i; \
M_CALL_INIT_SET(oplist, it.tree->tab[i].data, data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \
\
static inline it_t \
M_C(name, _insert_left)(it_t it, type const data) { \
M_C(name, _insert_child)(it_t pos, type const data) { \
it_t it = M_C(name, _insert_child_raw)(pos); \
M_CALL_INIT_SET(oplist, it.tree->tab[it.index].data, data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \
\
static inline it_t \
M_C(name, _insert_left_raw)(it_t it) { \
M_TR33_IT_CONTRACT(it, true); \
M_ASSERT(it.index != it.tree->root_index); \
m_tr33_index_t i = M_C3(m_tr33_, name, _alloc_node)(it.tree); \
@@ -518,13 +539,20 @@ typedef int32_t m_tr33_index_t;
} \
/* Return updated iterator on the inserted node */ \
it.index = i; \
M_CALL_INIT_SET(oplist, it.tree->tab[i].data, data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \
\
static inline it_t \
M_C(name, _insert_right)(it_t it, type const data) { \
M_C(name, _insert_left)(it_t pos, type const data) { \
it_t it = M_C(name, _insert_left_raw)(pos); \
M_CALL_INIT_SET(oplist, it.tree->tab[it.index].data, data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \
\
static inline it_t \
M_C(name, _insert_right_raw)(it_t it) { \
M_TR33_IT_CONTRACT(it, true); \
M_ASSERT(it.index != it.tree->root_index); \
m_tr33_index_t i = M_C3(m_tr33_, name, _alloc_node)(it.tree); \
@@ -537,7 +565,14 @@ typedef int32_t m_tr33_index_t;
it.tree->tab[it.index].right = i; \
/* Return updated iterator on the inserted node */ \
it.index = i; \
M_CALL_INIT_SET(oplist, it.tree->tab[i].data, data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \
\
static inline it_t \
M_C(name, _insert_right)(it_t pos, type const data) { \
it_t it = M_C(name, _insert_right_raw)(pos); \
M_CALL_INIT_SET(oplist, it.tree->tab[it.index].data, data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \