From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Kirill Shcherbatov Subject: [PATCH v4 3/4] box: refactor memtx_tree_delete_identical Date: Wed, 24 Jul 2019 10:36:09 +0300 Message-Id: <5ecc2db4034f2994510b6b9bb1399dd9cecda82c.1563953154.git.kshcherbatov@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: tarantool-patches@freelists.org, kostja@tarantool.org Cc: vdavydov.dev@gmail.com, Kirill Shcherbatov List-ID: Renamed memtx_tree_delete_identical to memtx_tree_delete_value because it is more representative name. Changed it's signature to return a deleted item, because it may require following destruction. This refactoring is required in scope of functional indexes. Needed for #1260 --- src/lib/salad/bps_tree.h | 9 ++++++--- src/box/memtx_tree.c | 4 ++-- test/unit/bps_tree.cc | 8 ++++---- test/unit/bps_tree.result | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/lib/salad/bps_tree.h b/src/lib/salad/bps_tree.h index 58d69bf66..db1343b67 100644 --- a/src/lib/salad/bps_tree.h +++ b/src/lib/salad/bps_tree.h @@ -360,7 +360,7 @@ typedef uint32_t bps_tree_block_id_t; #define bps_tree_insert _api_name(insert) #define bps_tree_insert_get_iterator _api_name(insert_get_iterator) #define bps_tree_delete _api_name(delete) -#define bps_tree_delete_identical _api_name(delete_identical) +#define bps_tree_delete_value _api_name(delete_value) #define bps_tree_size _api_name(size) #define bps_tree_mem_used _api_name(mem_used) #define bps_tree_random _api_name(random) @@ -4527,7 +4527,8 @@ bps_tree_delete(struct bps_tree *tree, bps_tree_elem_t elem) * found in tree or is not identical. */ static inline int -bps_tree_delete_identical(struct bps_tree *tree, bps_tree_elem_t elem) +bps_tree_delete_value(struct bps_tree *tree, bps_tree_elem_t elem, + bps_tree_elem_t *deleted_elem) { if (tree->root_id == (bps_tree_block_id_t)(-1)) return -1; @@ -4543,6 +4544,8 @@ bps_tree_delete_identical(struct bps_tree *tree, bps_tree_elem_t elem) if (!BPS_TREE_IDENTICAL(elem, leaf->elems[leaf_path_elem.insertion_point])) return -1; + if (deleted_elem != NULL) + *deleted_elem = leaf->elems[leaf_path_elem.insertion_point]; bps_tree_process_delete_leaf(tree, &leaf_path_elem); return 0; } @@ -6085,7 +6088,7 @@ bps_tree_debug_check_internal_functions(bool assertme) #undef bps_tree_find #undef bps_tree_insert #undef bps_tree_delete -#undef bps_tree_delete_identical +#undef bps_tree_delete_value #undef bps_tree_size #undef bps_tree_mem_used #undef bps_tree_random diff --git a/src/box/memtx_tree.c b/src/box/memtx_tree.c index 5f5848c69..41eb6dbec 100644 --- a/src/box/memtx_tree.c +++ b/src/box/memtx_tree.c @@ -667,7 +667,7 @@ memtx_tree_index_replace_multikey_rollback(struct memtx_tree_index *index, data.tuple = new_tuple; for (int i = 0; i < err_multikey_idx; i++) { data.hint = i; - memtx_tree_delete_identical(&index->tree, data); + memtx_tree_delete_value(&index->tree, data, NULL); } } @@ -717,7 +717,7 @@ memtx_tree_index_replace_multikey(struct index *base, struct tuple *old_tuple, tuple_multikey_count(old_tuple, cmp_def); for (int i = 0; (uint32_t) i < multikey_count; i++) { data.hint = i; - memtx_tree_delete_identical(&index->tree, data); + memtx_tree_delete_value(&index->tree, data, NULL); } } return 0; diff --git a/test/unit/bps_tree.cc b/test/unit/bps_tree.cc index a622ecc87..58b3e47c9 100644 --- a/test/unit/bps_tree.cc +++ b/test/unit/bps_tree.cc @@ -839,7 +839,7 @@ insert_get_iterator() } static void -delete_identical_check() +delete_value_check() { header(); struct_tree tree; @@ -847,11 +847,11 @@ delete_identical_check() struct elem_t e1 = {1, 1}; struct_tree_insert(&tree, e1, NULL); struct elem_t e2 = {1, 2}; - if (struct_tree_delete_identical(&tree, e2) == 0) + if (struct_tree_delete_value(&tree, e2, NULL) == 0) fail("deletion of the non-identical element must fail", "false"); if (struct_tree_find(&tree, 1) == NULL) fail("test non-identical element deletion failure", "false"); - if (struct_tree_delete_identical(&tree, e1) != 0) + if (struct_tree_delete_value(&tree, e1, NULL) != 0) fail("deletion of the identical element must not fail", "false"); if (struct_tree_find(&tree, 1) != NULL) fail("test identical element deletion completion", "false"); @@ -873,5 +873,5 @@ main(void) if (extents_count != 0) fail("memory leak!", "true"); insert_get_iterator(); - delete_identical_check(); + delete_value_check(); } diff --git a/test/unit/bps_tree.result b/test/unit/bps_tree.result index dc21bf340..130ec555c 100644 --- a/test/unit/bps_tree.result +++ b/test/unit/bps_tree.result @@ -280,5 +280,5 @@ Count: 10575 *** approximate_count: done *** *** insert_get_iterator *** *** insert_get_iterator: done *** - *** delete_identical_check *** - *** delete_identical_check: done *** + *** delete_value_check *** + *** delete_value_check: done *** -- 2.22.0