diff --git a/src/box/CMakeLists.txt b/src/box/CMakeLists.txt index e36a112be0876e5858c1486785d62c0c04089d66..6f61c5b3bf2061f6bf0fdb9ff74b535f966ac93b 100644 --- a/src/box/CMakeLists.txt +++ b/src/box/CMakeLists.txt @@ -35,6 +35,7 @@ add_library(box STATIC tuple_hash.cc key_def.cc index.cc + iterator_type.c memtx_index.cc memtx_hash.cc memtx_tree.cc diff --git a/src/box/index.cc b/src/box/index.cc index 425b7eaac8aef52977d4acf173fc17e177cf5c2e..596a72730accd8e0c4a136c0b0b74bff9d752735 100644 --- a/src/box/index.cc +++ b/src/box/index.cc @@ -39,24 +39,6 @@ #include "rmean.h" #include "info.h" -const char *iterator_type_strs[] = { - /* [ITER_EQ] = */ "EQ", - /* [ITER_REQ] = */ "REQ", - /* [ITER_ALL] = */ "ALL", - /* [ITER_LT] = */ "LT", - /* [ITER_LE] = */ "LE", - /* [ITER_GE] = */ "GE", - /* [ITER_GT] = */ "GT", - /* [ITER_BITS_ALL_SET] = */ "BITS_ALL_SET", - /* [ITER_BITS_ANY_SET] = */ "BITS_ANY_SET", - /* [ITER_BITS_ALL_NOT_SET] = */ "BITS_ALL_NOT_SET", - /* [ITER_OVERLAPS] = */ "OVERLAPS", - /* [ITER_NEIGHBOR] = */ "NEIGHBOR", -}; - -static_assert(sizeof(iterator_type_strs) / sizeof(const char *) == - iterator_type_MAX, "iterator_type_str constants"); - /* {{{ Utilities. **********************************************/ UnsupportedIndexFeature::UnsupportedIndexFeature(const char *file, diff --git a/src/box/index.h b/src/box/index.h index 381c6aae7094983c170b3a44c275d27ba6fd7449..96007b4957ea24265949cba03f2a92fff772b3be 100644 --- a/src/box/index.h +++ b/src/box/index.h @@ -32,6 +32,7 @@ */ #include <stdbool.h> #include "trivia/util.h" +#include "iterator_type.h" #if defined(__cplusplus) extern "C" { @@ -43,56 +44,6 @@ typedef struct tuple box_tuple_t; /** A space iterator */ typedef struct iterator box_iterator_t; -/** - * Controls how to iterate over tuples in an index. - * Different index types support different iterator types. - * For example, one can start iteration from a particular value - * (request key) and then retrieve all tuples where keys are - * greater or equal (= GE) to this key. - * - * If iterator type is not supported by the selected index type, - * iterator constructor must fail with ER_UNSUPPORTED. To be - * selectable for primary key, an index must support at least - * ITER_EQ and ITER_GE types. - * - * NULL value of request key corresponds to the first or last - * key in the index, depending on iteration direction. - * (first key for GE and GT types, and last key for LE and LT). - * Therefore, to iterate over all tuples in an index, one can - * use ITER_GE or ITER_LE iteration types with start key equal - * to NULL. - * For ITER_EQ, the key must not be NULL. - */ - -enum iterator_type { - /* ITER_EQ must be the first member for request_create */ - ITER_EQ = 0, /* key == x ASC order */ - ITER_REQ = 1, /* key == x DESC order */ - ITER_ALL = 2, /* all tuples */ - ITER_LT = 3, /* key < x */ - ITER_LE = 4, /* key <= x */ - ITER_GE = 5, /* key >= x */ - ITER_GT = 6, /* key > x */ - ITER_BITS_ALL_SET = 7, /* all bits from x are set in key */ - ITER_BITS_ANY_SET = 8, /* at least one x's bit is set */ - ITER_BITS_ALL_NOT_SET = 9, /* all bits are not set */ - ITER_OVERLAPS = 10, /* key overlaps x */ - ITER_NEIGHBOR = 11, /* tuples in distance ascending order from specified point */ - iterator_type_MAX = ITER_NEIGHBOR + 1 -}; - -/** - * Determine a direction of the given iterator type. - * That is -1 for REQ, LT and LE and +1 for all others. - */ -static inline int -iterator_direction(enum iterator_type type) -{ - const uint32_t reverse = - (1u << ITER_REQ) | (1u << ITER_LT) | (1u << ITER_LE); - return (reverse & (1u << type)) ? -1 : 1; -} - /** * Allocate and initialize iterator for space_id, index_id. * @@ -274,8 +225,6 @@ int box_index_info(uint32_t space_id, uint32_t index_id, struct info_handler *info); -extern const char *iterator_type_strs[]; - #if defined(__cplusplus) } /* extern "C" */ #include "key_def.h" @@ -290,12 +239,6 @@ struct iterator { struct Index *index; }; -static inline bool -iterator_type_is_reverse(enum iterator_type type) -{ - return type == ITER_REQ || type == ITER_LT || type == ITER_LE; -} - /** * Check that the key has correct part count and correct part size * for use in an index iterator. diff --git a/src/box/iterator_type.c b/src/box/iterator_type.c new file mode 100644 index 0000000000000000000000000000000000000000..5d6b55f21cef7359729704cdb49cbe65688558f1 --- /dev/null +++ b/src/box/iterator_type.c @@ -0,0 +1,50 @@ +/* + * Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include "iterator_type.h" +#include "trivia/util.h" + +const char *iterator_type_strs[] = { + /* [ITER_EQ] = */ "EQ", + /* [ITER_REQ] = */ "REQ", + /* [ITER_ALL] = */ "ALL", + /* [ITER_LT] = */ "LT", + /* [ITER_LE] = */ "LE", + /* [ITER_GE] = */ "GE", + /* [ITER_GT] = */ "GT", + /* [ITER_BITS_ALL_SET] = */ "BITS_ALL_SET", + /* [ITER_BITS_ANY_SET] = */ "BITS_ANY_SET", + /* [ITER_BITS_ALL_NOT_SET] = */ "BITS_ALL_NOT_SET", + /* [ITER_OVERLAPS] = */ "OVERLAPS", + /* [ITER_NEIGHBOR] = */ "NEIGHBOR", +}; + +static_assert(sizeof(iterator_type_strs) / sizeof(const char *) == + iterator_type_MAX, "iterator_type_str constants"); diff --git a/src/box/iterator_type.h b/src/box/iterator_type.h new file mode 100644 index 0000000000000000000000000000000000000000..445c1110d848bf2e5a7af8bc9db00b96411df7a6 --- /dev/null +++ b/src/box/iterator_type.h @@ -0,0 +1,101 @@ +#ifndef TARANTOOL_BOX_ITERATOR_TYPE_H_INCLUDED +#define TARANTOOL_BOX_ITERATOR_TYPE_H_INCLUDED +/* + * Copyright 2010-2017, Tarantool AUTHORS, please see AUTHORS file. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the + * following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR + * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <stdbool.h> + +#if defined(__cplusplus) +extern "C" { +#endif /* defined(__cplusplus) */ + +/** + * Controls how to iterate over tuples in an index. + * Different index types support different iterator types. + * For example, one can start iteration from a particular value + * (request key) and then retrieve all tuples where keys are + * greater or equal (= GE) to this key. + * + * If iterator type is not supported by the selected index type, + * iterator constructor must fail with ER_UNSUPPORTED. To be + * selectable for primary key, an index must support at least + * ITER_EQ and ITER_GE types. + * + * NULL value of request key corresponds to the first or last + * key in the index, depending on iteration direction. + * (first key for GE and GT types, and last key for LE and LT). + * Therefore, to iterate over all tuples in an index, one can + * use ITER_GE or ITER_LE iteration types with start key equal + * to NULL. + * For ITER_EQ, the key must not be NULL. + */ +enum iterator_type { + /* ITER_EQ must be the first member for request_create */ + ITER_EQ = 0, /* key == x ASC order */ + ITER_REQ = 1, /* key == x DESC order */ + ITER_ALL = 2, /* all tuples */ + ITER_LT = 3, /* key < x */ + ITER_LE = 4, /* key <= x */ + ITER_GE = 5, /* key >= x */ + ITER_GT = 6, /* key > x */ + ITER_BITS_ALL_SET = 7, /* all bits from x are set in key */ + ITER_BITS_ANY_SET = 8, /* at least one x's bit is set */ + ITER_BITS_ALL_NOT_SET = 9, /* all bits are not set */ + ITER_OVERLAPS = 10, /* key overlaps x */ + ITER_NEIGHBOR = 11, /* tuples in distance ascending order from specified point */ + iterator_type_MAX +}; + +extern const char *iterator_type_strs[]; + +/** + * Determine a direction of the given iterator type. + * That is -1 for REQ, LT and LE and +1 for all others. + */ +static inline int +iterator_direction(enum iterator_type type) +{ + const unsigned reverse = + (1u << ITER_REQ) | (1u << ITER_LT) | (1u << ITER_LE); + return (reverse & (1u << type)) ? -1 : 1; +} + +static inline bool +iterator_type_is_reverse(enum iterator_type type) +{ + return type == ITER_REQ || type == ITER_LT || type == ITER_LE; +} + +#if defined(__cplusplus) +} /* extern "C" */ +#endif /* defined(__cplusplus) */ + +#endif /* TARANTOOL_BOX_ITERATOR_TYPE_H_INCLUDED */ diff --git a/src/box/vy_cache.h b/src/box/vy_cache.h index ed4453e5f430337ab20d11e25a5fbcc33fdea290..4714fb715ecda5a2906c565ed00e474a32b574e4 100644 --- a/src/box/vy_cache.h +++ b/src/box/vy_cache.h @@ -36,7 +36,7 @@ #include <small/rlist.h> -#include "index.h" /* enum iterator_type */ +#include "iterator_type.h" #include "vy_stmt.h" /* for comparators */ #include "vy_stmt_iterator.h" /* struct vy_stmt_iterator */ #include "vy_stat.h" diff --git a/src/box/vy_mem.h b/src/box/vy_mem.h index 4e8df5b66d23e39d4bd9cafd52d4a3510b8d4092..c305ad80040d4b1e0b2e583cee9c588f12ed56a7 100644 --- a/src/box/vy_mem.h +++ b/src/box/vy_mem.h @@ -37,7 +37,7 @@ #include <small/rlist.h> #include "ipc.h" -#include "index.h" /* enum iterator_type */ +#include "iterator_type.h" #include "vy_stmt.h" /* for comparators */ #include "vy_stmt_iterator.h" /* struct vy_stmt_iterator */ #include "vy_stat.h" diff --git a/src/box/vy_run.h b/src/box/vy_run.h index 92556e77d78f6175d7f281e95bc24560277d8518..3958d7bb3822db64ff90e3c51e2077c561725a83 100644 --- a/src/box/vy_run.h +++ b/src/box/vy_run.h @@ -35,7 +35,7 @@ #include <stdbool.h> #include "ipc.h" -#include "index.h" /* enum iterator_type */ +#include "iterator_type.h" #include "vy_stmt.h" /* for comparators */ #include "vy_stmt_iterator.h" /* struct vy_stmt_iterator */ #include "vy_stat.h"