Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: vdavydov.dev@gmail.com, Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [PATCH v4 01/14] box: refactor key_def_find routine
Date: Thu, 11 Oct 2018 10:58:41 +0300	[thread overview]
Message-ID: <603e181a38f0c1e6bb7fe9b4d5ddced9cba09855.1539244271.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1539244271.git.kshcherbatov@tarantool.org>
In-Reply-To: <cover.1539244271.git.kshcherbatov@tarantool.org>

Replaced key_def_find with a new key_def_contains_part routine
that checks if key_def contains specified part. In all cases
legacy key_def_find has been used for such purpose. New API
is more convenient for complex key_part that will appear with
JSON paths introduction.

Part of #1012.
---
 src/box/key_def.c | 17 +++++++++--------
 src/box/key_def.h | 10 ++++------
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/src/box/key_def.c b/src/box/key_def.c
index 545b5da..67b517f 100644
--- a/src/box/key_def.c
+++ b/src/box/key_def.c
@@ -483,16 +483,17 @@ key_def_decode_parts_160(struct key_part_def *parts, uint32_t part_count,
 	return 0;
 }
 
-const struct key_part *
-key_def_find(const struct key_def *key_def, uint32_t fieldno)
+bool
+key_def_contains_part(const struct key_def *key_def,
+		      const struct key_part *to_find)
 {
 	const struct key_part *part = key_def->parts;
 	const struct key_part *end = part + key_def->part_count;
 	for (; part != end; part++) {
-		if (part->fieldno == fieldno)
-			return part;
+		if (part->fieldno == to_find->fieldno)
+			return true;
 	}
-	return NULL;
+	return false;
 }
 
 bool
@@ -501,7 +502,7 @@ key_def_contains(const struct key_def *first, const struct key_def *second)
 	const struct key_part *part = second->parts;
 	const struct key_part *end = part + second->part_count;
 	for (; part != end; part++) {
-		if (key_def_find(first, part->fieldno) == NULL)
+		if (!key_def_contains_part(first, part))
 			return false;
 	}
 	return true;
@@ -518,7 +519,7 @@ key_def_merge(const struct key_def *first, const struct key_def *second)
 	const struct key_part *part = second->parts;
 	const struct key_part *end = part + second->part_count;
 	for (; part != end; part++) {
-		if (key_def_find(first, part->fieldno))
+		if (key_def_contains_part(first, part))
 			--new_part_count;
 	}
 
@@ -548,7 +549,7 @@ key_def_merge(const struct key_def *first, const struct key_def *second)
 	part = second->parts;
 	end = part + second->part_count;
 	for (; part != end; part++) {
-		if (key_def_find(first, part->fieldno))
+		if (key_def_contains_part(first, part))
 			continue;
 		key_def_set_part(new_def, pos++, part->fieldno, part->type,
 				 part->is_nullable, part->coll, part->coll_id);
diff --git a/src/box/key_def.h b/src/box/key_def.h
index df85321..37b9045 100644
--- a/src/box/key_def.h
+++ b/src/box/key_def.h
@@ -301,12 +301,10 @@ key_def_decode_parts_160(struct key_part_def *parts, uint32_t part_count,
 			 const char **data, const struct field_def *fields,
 			 uint32_t field_count);
 
-/**
- * Returns the part in index_def->parts for the specified fieldno.
- * If fieldno is not in index_def->parts returns NULL.
- */
-const struct key_part *
-key_def_find(const struct key_def *key_def, uint32_t fieldno);
+/** Check if @a key_def contains @a to_find part. */
+bool
+key_def_contains_part(const struct key_def *key_def,
+		      const struct key_part *to_find);
 
 /**
  * Check if key definition @a first contains all parts of
-- 
2.7.4

  reply	other threads:[~2018-10-11  7:58 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-11  7:58 [PATCH v4 00/14] box: indexes by JSON path Kirill Shcherbatov
2018-10-11  7:58 ` Kirill Shcherbatov [this message]
2018-10-15 17:27   ` [PATCH v4 01/14] box: refactor key_def_find routine Vladimir Davydov
2018-10-11  7:58 ` [PATCH v4 10/14] box: introduce JSON indexes Kirill Shcherbatov
2018-10-16  9:33   ` Vladimir Davydov
2018-10-11  7:58 ` [PATCH v4 11/14] box: introduce has_json_paths flag in templates Kirill Shcherbatov
2018-10-11  7:58 ` [PATCH v4 12/14] box: tune tuple_field_raw_by_path for indexed data Kirill Shcherbatov
2018-10-11  7:58 ` [PATCH v4 13/14] box: introduce offset slot cache in key_part Kirill Shcherbatov
2018-10-11  7:58 ` [PATCH v4 14/14] box: specify indexes in user-friendly form Kirill Shcherbatov
2018-10-11  7:58 ` [PATCH v4 02/14] box: introduce key_def_parts_are_sequential Kirill Shcherbatov
2018-10-15 17:29   ` Vladimir Davydov
2018-10-11  7:58 ` [PATCH v4 03/14] box: introduce tuple_field_by_relative_path Kirill Shcherbatov
2018-10-15 17:46   ` Vladimir Davydov
2018-10-11  7:58 ` [PATCH v4 04/14] box: introduce tuple_format_add_key_part Kirill Shcherbatov
2018-10-15 19:39   ` Vladimir Davydov
2018-10-11  7:58 ` [tarantool-patches] [PATCH v4 05/14] box: introduce tuple_format_sizeof routine Kirill Shcherbatov
2018-10-15 17:52   ` Vladimir Davydov
2018-10-11  7:58 ` [PATCH v4 06/14] box: move tuple_field_go_to_{index,key} definition Kirill Shcherbatov
2018-10-16  8:15   ` Vladimir Davydov
2018-10-11  7:58 ` [PATCH v4 07/14] box: drop format const qualifier in *init_field_map Kirill Shcherbatov
2018-10-11  7:58 ` [PATCH v4 08/14] lib: implement JSON tree class for json library Kirill Shcherbatov
2018-10-16  8:26   ` Vladimir Davydov
2018-10-11  7:58 ` [PATCH v4 09/14] lib: introduce json_path_normalize routine Kirill Shcherbatov
2018-10-16  8:39   ` Vladimir Davydov

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=603e181a38f0c1e6bb7fe9b4d5ddced9cba09855.1539244271.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=vdavydov.dev@gmail.com \
    --subject='Re: [PATCH v4 01/14] box: refactor key_def_find routine' \
    /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