From 121339d94868da92c3cd6aa3d3268bb005d10bdb Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Mon, 1 Aug 2022 22:17:26 +0200 Subject: [PATCH] Add _move_* functions for generic tree. --- m-tree.h | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/m-tree.h b/m-tree.h index 2b7cbcd5..73c7e1fe 100644 --- a/m-tree.h +++ b/m-tree.h @@ -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).