Add _move_* functions for generic tree.

This commit is contained in:
Patrick Pelissier committed 2022-08-01 22:17:26 +02:00
1 parent c5bb84013a
commit 121339d948
1 file changed
+40 -2
+40 -2
View File
@@ -460,6 +460,14 @@ typedef int32_t m_tr33_index_t;
} \
\
static inline it_t \
M_C(name, _move_up)(it_t pos, type *data) { \
it_t it = M_C(name, _insert_up_raw)(pos); \
M_DO_INIT_MOVE(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); \
@@ -489,6 +497,14 @@ typedef int32_t m_tr33_index_t;
} \
\
static inline it_t \
M_C(name, _move_down)(it_t pos, type *data) { \
it_t it = M_C(name, _insert_down_raw)(pos); \
M_DO_INIT_MOVE(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 \
@@ -520,6 +536,14 @@ typedef int32_t m_tr33_index_t;
} \
\
static inline it_t \
M_C(name, _move_child)(it_t pos, type *data) { \
it_t it = M_C(name, _insert_child_raw)(pos); \
M_DO_INIT_MOVE(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); \
@@ -552,6 +576,14 @@ typedef int32_t m_tr33_index_t;
} \
\
static inline it_t \
M_C(name, _move_left)(it_t pos, type *data) { \
it_t it = M_C(name, _insert_left_raw)(pos); \
M_DO_INIT_MOVE(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); \
@@ -577,6 +609,14 @@ typedef int32_t m_tr33_index_t;
return it; \
} \
\
static inline it_t \
M_C(name, _move_right)(it_t pos, type *data) { \
it_t it = M_C(name, _insert_right_raw)(pos); \
M_DO_INIT_MOVE(oplist, it.tree->tab[it.index].data, *data); \
M_TR33_IT_CONTRACT(it, true); \
return it; \
} \
\
static inline bool \
M_C(name, _it_up)(it_t *it) { \
M_ASSERT(it != NULL); \
@@ -1414,9 +1454,7 @@ exit: \
, /* No IN_STR */ ) \
// TODO:
// * insertion function with move semantics (or _raw methods?)
// * emplace insertion
// * I/O
// * Allocate one more "spare" member in the array (alloc is capacity+1),
// so that we don't need to write if (i != M_TR33_NO_NODE) { tab[i] = j; }
// but simply "tab[i] = j;" (avoid one conditional branch).