Skip to content
Snippets Groups Projects
Commit 63fe5e6d authored by Vladimir Davydov's avatar Vladimir Davydov
Browse files

Move iterator_type to its own source file

Including index.h just for the sake of iterator_type, as we do in
vy_run.h and vy_mem.h, is a bit of overkill. Let's move its definition
to a separate source file, iterator_type.h.
parent e0dae391
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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,
......
......@@ -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.
......
/*
* 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");
#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 */
......@@ -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"
......
......@@ -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"
......
......@@ -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"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment