Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, kostja@tarantool.org
Cc: vdavydov.dev@gmail.com, Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [PATCH v4 3/4] box: refactor memtx_tree_delete_identical
Date: Wed, 24 Jul 2019 10:36:09 +0300	[thread overview]
Message-ID: <5ecc2db4034f2994510b6b9bb1399dd9cecda82c.1563953154.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1563953154.git.kshcherbatov@tarantool.org>

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

  parent reply	other threads:[~2019-07-24  7:36 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-24  7:36 [PATCH v4 0/4] box: functional indexes Kirill Shcherbatov
2019-07-24  7:36 ` [PATCH v4 1/4] box: introduce tuple_chunk infrastructure Kirill Shcherbatov
2019-07-24  7:36 ` [PATCH v4 2/4] box: generalize memtx_multikey_tree methods Kirill Shcherbatov
2019-07-24 19:24   ` Konstantin Osipov
2019-07-24  7:36 ` Kirill Shcherbatov [this message]
2019-07-24 19:24   ` [PATCH v4 3/4] box: refactor memtx_tree_delete_identical Konstantin Osipov
2019-07-24  7:36 ` [PATCH v4 4/4] box: introduce functional indexes Kirill Shcherbatov
2019-07-24 12:24   ` [tarantool-patches] " Kirill Shcherbatov
2019-07-24 19:41   ` Konstantin Osipov
2019-07-24 20:04   ` Konstantin Osipov
2019-07-24 20:22   ` Konstantin Osipov
2019-07-25 11:20     ` [tarantool-patches] " Kirill Shcherbatov
2019-07-24 20:44   ` Konstantin Osipov
2019-07-25 11:22     ` [tarantool-patches] " Kirill Shcherbatov
2019-07-24 21:07   ` Konstantin Osipov
2019-07-25  8:27     ` [tarantool-patches] " Kirill Shcherbatov
2019-07-25  8:40       ` Konstantin Osipov
2019-07-25 11:18         ` Kirill Shcherbatov
2019-07-24 21:17   ` Konstantin Osipov
2019-07-24 21:56   ` Konstantin Osipov
2019-07-25  8:33     ` [tarantool-patches] " Kirill Shcherbatov
2019-07-24 12:25 ` [tarantool-patches] [PATCH v4 4/5] box: fix memtx_tree_index_build_array_deduplicate Kirill Shcherbatov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5ecc2db4034f2994510b6b9bb1399dd9cecda82c.1563953154.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH v4 3/4] box: refactor memtx_tree_delete_identical' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox