From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Kirill Shcherbatov Subject: [PATCH v2 1/4] box: move memtx_tree implementation to source file Date: Wed, 13 Feb 2019 12:32:25 +0300 Message-Id: <0e4dceb9b4dd6ae72bca08823ad7b5a8a6f85ce6.1550050245.git.kshcherbatov@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit To: tarantool-patches@freelists.org, kostja@tarantool.org, vdavydov.dev@gmail.com Cc: Kirill Shcherbatov List-ID: Refactored memtx_tree code so that memtx_tree.h contained only the signature of the tree object constructor memtx_tree_index_new, while all implementation details were in memtx_tree.c. This will further allow to template the implementation details. Needed for #3961 --- src/box/memtx_tree.c | 62 ++++++++++++++++++++++++++++++++++++++-- src/box/memtx_tree.h | 68 ++------------------------------------------ 2 files changed, 63 insertions(+), 67 deletions(-) diff --git a/src/box/memtx_tree.c b/src/box/memtx_tree.c index f851fb869..2e8adb682 100644 --- a/src/box/memtx_tree.c +++ b/src/box/memtx_tree.c @@ -39,6 +39,64 @@ #include #include +/** + * Struct that is used as a key in BPS tree definition. + */ +struct memtx_tree_key_data { + /** Sequence of msgpacked search fields. */ + const char *key; + /** Number of msgpacked search fields. */ + uint32_t part_count; +}; + +/** + * BPS tree element vs key comparator. + * Defined in header in order to allow compiler to inline it. + * @param tuple - tuple to compare. + * @param key_data - key to compare with. + * @param def - key definition. + * @retval 0 if tuple == key in terms of def. + * @retval <0 if tuple < key in terms of def. + * @retval >0 if tuple > key in terms of def. + */ +static int +memtx_tree_compare_key(const struct tuple *tuple, + const struct memtx_tree_key_data *key_data, + struct key_def *def) +{ + return tuple_compare_with_key(tuple, key_data->key, + key_data->part_count, def); +} + +#define BPS_TREE_NAME memtx_tree +#define BPS_TREE_BLOCK_SIZE (512) +#define BPS_TREE_EXTENT_SIZE MEMTX_EXTENT_SIZE +#define BPS_TREE_COMPARE(a, b, arg) tuple_compare(a, b, arg) +#define BPS_TREE_COMPARE_KEY(a, b, arg) memtx_tree_compare_key(a, b, arg) +#define bps_tree_elem_t struct tuple * +#define bps_tree_key_t struct memtx_tree_key_data * +#define bps_tree_arg_t struct key_def * + +#include "salad/bps_tree.h" + +#undef BPS_TREE_NAME +#undef BPS_TREE_BLOCK_SIZE +#undef BPS_TREE_EXTENT_SIZE +#undef BPS_TREE_COMPARE +#undef BPS_TREE_COMPARE_KEY +#undef bps_tree_elem_t +#undef bps_tree_key_t +#undef bps_tree_arg_t + +struct memtx_tree_index { + struct index base; + struct memtx_tree tree; + struct tuple **build_array; + size_t build_array_size, build_array_alloc_size; + struct memtx_gc_task gc_task; + struct memtx_tree_iterator gc_iterator; +}; + /* {{{ Utilities. *************************************************/ static int @@ -683,7 +741,7 @@ static const struct index_vtab memtx_tree_index_vtab = { /* .end_build = */ memtx_tree_index_end_build, }; -struct memtx_tree_index * +struct index * memtx_tree_index_new(struct memtx_engine *memtx, struct index_def *def) { if (!mempool_is_initialized(&memtx->tree_iterator_pool)) { @@ -707,5 +765,5 @@ memtx_tree_index_new(struct memtx_engine *memtx, struct index_def *def) struct key_def *cmp_def = memtx_tree_index_cmp_def(index); memtx_tree_create(&index->tree, cmp_def, memtx_index_extent_alloc, memtx_index_extent_free, memtx); - return index; + return &index->base; } diff --git a/src/box/memtx_tree.h b/src/box/memtx_tree.h index bbc8b2419..edeaebab9 100644 --- a/src/box/memtx_tree.h +++ b/src/box/memtx_tree.h @@ -30,78 +30,16 @@ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ -#include -#include - -#include "index.h" -#include "memtx_engine.h" #if defined(__cplusplus) extern "C" { #endif /* defined(__cplusplus) */ +struct index; +struct index_def; struct memtx_engine; -/** - * Struct that is used as a key in BPS tree definition. - */ -struct memtx_tree_key_data -{ - /** Sequence of msgpacked search fields */ - const char *key; - /** Number of msgpacked search fields */ - uint32_t part_count; -}; - -/** - * BPS tree element vs key comparator. - * Defined in header in order to allow compiler to inline it. - * @param tuple - tuple to compare. - * @param key_data - key to compare with. - * @param def - key definition. - * @retval 0 if tuple == key in terms of def. - * @retval <0 if tuple < key in terms of def. - * @retval >0 if tuple > key in terms of def. - */ -static inline int -memtx_tree_compare_key(const struct tuple *tuple, - const struct memtx_tree_key_data *key_data, - struct key_def *def) -{ - return tuple_compare_with_key(tuple, key_data->key, - key_data->part_count, def); -} - -#define BPS_TREE_NAME memtx_tree -#define BPS_TREE_BLOCK_SIZE (512) -#define BPS_TREE_EXTENT_SIZE MEMTX_EXTENT_SIZE -#define BPS_TREE_COMPARE(a, b, arg) tuple_compare(a, b, arg) -#define BPS_TREE_COMPARE_KEY(a, b, arg) memtx_tree_compare_key(a, b, arg) -#define bps_tree_elem_t struct tuple * -#define bps_tree_key_t struct memtx_tree_key_data * -#define bps_tree_arg_t struct key_def * - -#include "salad/bps_tree.h" - -#undef BPS_TREE_NAME -#undef BPS_TREE_BLOCK_SIZE -#undef BPS_TREE_EXTENT_SIZE -#undef BPS_TREE_COMPARE -#undef BPS_TREE_COMPARE_KEY -#undef bps_tree_elem_t -#undef bps_tree_key_t -#undef bps_tree_arg_t - -struct memtx_tree_index { - struct index base; - struct memtx_tree tree; - struct tuple **build_array; - size_t build_array_size, build_array_alloc_size; - struct memtx_gc_task gc_task; - struct memtx_tree_iterator gc_iterator; -}; - -struct memtx_tree_index * +struct index * memtx_tree_index_new(struct memtx_engine *memtx, struct index_def *def); #if defined(__cplusplus) -- 2.20.1