1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
|
#ifndef TARANTOOL_LIB_BITSET_ITERATOR_H_INCLUDED
#define TARANTOOL_LIB_BITSET_ITERATOR_H_INCLUDED
/*
* 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.
*/
/**
* @file
* @brief Iterator for @link bitset @endlink objects with
* expression support.
*
* @link bitset_iterator @endlink is used to iterate over a result
* of the evaluation a @link bitset_expr logical expression
* @endlink on a set of bitsets. The iterator evaluates its
* expression on the fly, without producing temporary bitsets.
* Each iteration (@link bitset_iterator_next @endlink) returns
* the next position where a given expression evaluates to true on
* a given set of bitsets.
*
* @see expr.h
*/
#include <lib/bitset/bitset.h>
#include <lib/bitset/expr.h>
#if defined(__cplusplus)
extern "C" {
#endif /* defined(__cplusplus) */
/** @cond false **/
struct bitset_iterator_conj;
/** @endcond **/
/**
* @brief Bitset Iterator
*/
struct bitset_iterator {
/** @cond false **/
size_t size;
size_t capacity;
struct bitset_iterator_conj *conjs;
struct bitset_page *page;
struct bitset_page *page_tmp;
void *(*realloc)(void *ptr, size_t size);
struct bit_iterator page_it;
/** @endcond **/
};
/**
* @brief Construct \a it.
*
* The created iterator must be initialized by
* @link bitset_iterator_init @endlink method before first usage.
* @param it bitset iterator
* @param realloc memory allocator to use
*/
void
bitset_iterator_create(struct bitset_iterator *it,
void *(*realloc)(void *ptr, size_t size));
/**
* @brief Destruct \a it.
* @param it bitset iterator
*/
void
bitset_iterator_destroy(struct bitset_iterator *it);
/**
* @brief Initialize the \a it using \a expr and \a bitsets and rewind the
* iterator to the start position.
*
* @note It is safe to reinitialize an iterator with a new expression and new
* bitsets. All internal buffers are safely reused in this case with minimal
* number of new allocations.
*
* @note @a expr object is only used during initialization time and can be
* safetly reused or destroyed just after this call.
*
* @param it bitset iterator
* @param expr bitset expression
* @param bitsets array of pointers to bitsets that should be used to bind
* the expression parameters.
* @param size of @a bitsets array
* @retval 0 on success
* @retval -1 on memory error
* @see expr.h
*/
int
bitset_iterator_init(struct bitset_iterator *it, struct bitset_expr *expr,
struct bitset **bitsets, size_t bitsets_size);
/**
* @brief Rewind the \a it to the start position.
* @param it bitset iterator
* @see @link bitset_iterator_init @endlink
*/
void
bitset_iterator_rewind(struct bitset_iterator *it);
/**
* @brief Move \a it to a next position
* @param it bitset iterator
* @return the next offset where the expression evaluates to true
* or SIZE_MAX if there is no more bits in the result set.
* @see @link bitset_iterator_init @endlink
*/
size_t
bitset_iterator_next(struct bitset_iterator *it);
#if defined(__cplusplus)
}
#endif /* defined(__cplusplus) */
#endif /* TARANTOOL_LIB_BITSET_ITERATOR_H_INCLUDED */
|