Coverage Report

Created: 2024-11-20 12:30

/var/local/thirdparty/installed/include/roaring/containers/array.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * array.h
3
 *
4
 */
5
6
#ifndef INCLUDE_CONTAINERS_ARRAY_H_
7
#define INCLUDE_CONTAINERS_ARRAY_H_
8
9
#include <string.h>
10
11
#include <roaring/portability.h>
12
#include <roaring/roaring_types.h>  // roaring_iterator
13
#include <roaring/array_util.h>  // binarySearch()/memequals() for inlining
14
15
#include <roaring/containers/container_defs.h>  // container_t, perfparameters
16
17
#ifdef __cplusplus
18
extern "C" { namespace roaring {
19
20
// Note: in pure C++ code, you should avoid putting `using` in header files
21
using api::roaring_iterator;
22
using api::roaring_iterator64;
23
24
namespace internal {
25
#endif
26
27
/* Containers with DEFAULT_MAX_SIZE or less integers should be arrays */
28
enum { DEFAULT_MAX_SIZE = 4096 };
29
30
/* struct array_container - sparse representation of a bitmap
31
 *
32
 * @cardinality: number of indices in `array` (and the bitmap)
33
 * @capacity:    allocated size of `array`
34
 * @array:       sorted list of integers
35
 */
36
STRUCT_CONTAINER(array_container_s) {
37
    int32_t cardinality;
38
    int32_t capacity;
39
    uint16_t *array;
40
};
41
42
typedef struct array_container_s array_container_t;
43
44
#define CAST_array(c)         CAST(array_container_t *, c)  // safer downcast
45
#define const_CAST_array(c)   CAST(const array_container_t *, c)
46
#define movable_CAST_array(c) movable_CAST(array_container_t **, c)
47
48
/* Create a new array with default. Return NULL in case of failure. See also
49
 * array_container_create_given_capacity. */
50
array_container_t *array_container_create(void);
51
52
/* Create a new array with a specified capacity size. Return NULL in case of
53
 * failure. */
54
array_container_t *array_container_create_given_capacity(int32_t size);
55
56
/* Create a new array containing all values in [min,max). */
57
array_container_t * array_container_create_range(uint32_t min, uint32_t max);
58
59
/*
60
 * Shrink the capacity to the actual size, return the number of bytes saved.
61
 */
62
int array_container_shrink_to_fit(array_container_t *src);
63
64
/* Free memory owned by `array'. */
65
void array_container_free(array_container_t *array);
66
67
/* Duplicate container */
68
array_container_t *array_container_clone(const array_container_t *src);
69
70
/* Get the cardinality of `array'. */
71
ALLOW_UNALIGNED
72
0
static inline int array_container_cardinality(const array_container_t *array) {
73
0
    return array->cardinality;
74
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL27array_container_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL27array_container_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL27array_container_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL27array_container_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL27array_container_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL27array_container_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL27array_container_cardinalityEPKNS0_17array_container_sE
75
76
static inline bool array_container_nonzero_cardinality(
77
0
    const array_container_t *array) {
78
0
    return array->cardinality > 0;
79
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL35array_container_nonzero_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL35array_container_nonzero_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL35array_container_nonzero_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL35array_container_nonzero_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL35array_container_nonzero_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL35array_container_nonzero_cardinalityEPKNS0_17array_container_sE
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL35array_container_nonzero_cardinalityEPKNS0_17array_container_sE
80
81
/* Copy one container into another. We assume that they are distinct. */
82
void array_container_copy(const array_container_t *src, array_container_t *dst);
83
84
/*  Add all the values in [min,max) (included) at a distance k*step from min.
85
    The container must have a size less or equal to DEFAULT_MAX_SIZE after this
86
   addition. */
87
void array_container_add_from_range(array_container_t *arr, uint32_t min,
88
                                    uint32_t max, uint16_t step);
89
90
91
0
static inline bool array_container_empty(const array_container_t *array) {
92
0
    return array->cardinality == 0;
93
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL21array_container_emptyEPKNS0_17array_container_sE
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL21array_container_emptyEPKNS0_17array_container_sE
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL21array_container_emptyEPKNS0_17array_container_sE
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL21array_container_emptyEPKNS0_17array_container_sE
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL21array_container_emptyEPKNS0_17array_container_sE
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL21array_container_emptyEPKNS0_17array_container_sE
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL21array_container_emptyEPKNS0_17array_container_sE
94
95
/* check whether the cardinality is equal to the capacity (this does not mean
96
* that it contains 1<<16 elements) */
97
0
static inline bool array_container_full(const array_container_t *array) {
98
0
    return array->cardinality == array->capacity;
99
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL20array_container_fullEPKNS0_17array_container_sE
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL20array_container_fullEPKNS0_17array_container_sE
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL20array_container_fullEPKNS0_17array_container_sE
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL20array_container_fullEPKNS0_17array_container_sE
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL20array_container_fullEPKNS0_17array_container_sE
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL20array_container_fullEPKNS0_17array_container_sE
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL20array_container_fullEPKNS0_17array_container_sE
100
101
102
/* Compute the union of `src_1' and `src_2' and write the result to `dst'
103
 * It is assumed that `dst' is distinct from both `src_1' and `src_2'. */
104
void array_container_union(const array_container_t *src_1,
105
                           const array_container_t *src_2,
106
                           array_container_t *dst);
107
108
/* symmetric difference, see array_container_union */
109
void array_container_xor(const array_container_t *array_1,
110
                         const array_container_t *array_2,
111
                         array_container_t *out);
112
113
/* Computes the intersection of src_1 and src_2 and write the result to
114
 * dst. It is assumed that dst is distinct from both src_1 and src_2. */
115
void array_container_intersection(const array_container_t *src_1,
116
                                  const array_container_t *src_2,
117
                                  array_container_t *dst);
118
119
/* Check whether src_1 and src_2 intersect. */
120
bool array_container_intersect(const array_container_t *src_1,
121
                                  const array_container_t *src_2);
122
123
124
/* computers the size of the intersection between two arrays.
125
 */
126
int array_container_intersection_cardinality(const array_container_t *src_1,
127
                                             const array_container_t *src_2);
128
129
/* computes the intersection of array1 and array2 and write the result to
130
 * array1.
131
 * */
132
void array_container_intersection_inplace(array_container_t *src_1,
133
                                          const array_container_t *src_2);
134
135
/*
136
 * Write out the 16-bit integers contained in this container as a list of 32-bit
137
 * integers using base
138
 * as the starting value (it might be expected that base has zeros in its 16
139
 * least significant bits).
140
 * The function returns the number of values written.
141
 * The caller is responsible for allocating enough memory in out.
142
 */
143
int array_container_to_uint32_array(void *vout, const array_container_t *cont,
144
                                    uint32_t base);
145
146
/* Compute the number of runs */
147
int32_t array_container_number_of_runs(const array_container_t *ac);
148
149
/*
150
 * Print this container using printf (useful for debugging).
151
 */
152
void array_container_printf(const array_container_t *v);
153
154
/*
155
 * Print this container using printf as a comma-separated list of 32-bit
156
 * integers starting at base.
157
 */
158
void array_container_printf_as_uint32_array(const array_container_t *v,
159
                                            uint32_t base);
160
161
bool array_container_validate(const array_container_t *v, const char **reason);
162
163
/**
164
 * Return the serialized size in bytes of a container having cardinality "card".
165
 */
166
0
static inline int32_t array_container_serialized_size_in_bytes(int32_t card) {
167
0
    return card * 2 + 2;
168
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL40array_container_serialized_size_in_bytesEi
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL40array_container_serialized_size_in_bytesEi
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL40array_container_serialized_size_in_bytesEi
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL40array_container_serialized_size_in_bytesEi
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL40array_container_serialized_size_in_bytesEi
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL40array_container_serialized_size_in_bytesEi
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL40array_container_serialized_size_in_bytesEi
169
170
/**
171
 * Increase capacity to at least min.
172
 * Whether the existing data needs to be copied over depends on the "preserve"
173
 * parameter. If preserve is false, then the new content will be uninitialized,
174
 * otherwise the old content is copied.
175
 */
176
void array_container_grow(array_container_t *container, int32_t min,
177
                          bool preserve);
178
179
bool array_container_iterate(const array_container_t *cont, uint32_t base,
180
                             roaring_iterator iterator, void *ptr);
181
bool array_container_iterate64(const array_container_t *cont, uint32_t base,
182
                               roaring_iterator64 iterator, uint64_t high_bits,
183
                               void *ptr);
184
185
/**
186
 * Writes the underlying array to buf, outputs how many bytes were written.
187
 * This is meant to be byte-by-byte compatible with the Java and Go versions of
188
 * Roaring.
189
 * The number of bytes written should be
190
 * array_container_size_in_bytes(container).
191
 *
192
 */
193
int32_t array_container_write(const array_container_t *container, char *buf);
194
/**
195
 * Reads the instance from buf, outputs how many bytes were read.
196
 * This is meant to be byte-by-byte compatible with the Java and Go versions of
197
 * Roaring.
198
 * The number of bytes read should be array_container_size_in_bytes(container).
199
 * You need to provide the (known) cardinality.
200
 */
201
int32_t array_container_read(int32_t cardinality, array_container_t *container,
202
                             const char *buf);
203
204
/**
205
 * Return the serialized size in bytes of a container (see
206
 * bitset_container_write)
207
 * This is meant to be compatible with the Java and Go versions of Roaring and
208
 * assumes
209
 * that the cardinality of the container is already known.
210
 *
211
 */
212
static inline int32_t array_container_size_in_bytes(
213
0
    const array_container_t *container) {
214
0
    return container->cardinality * sizeof(uint16_t);
215
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL29array_container_size_in_bytesEPKNS0_17array_container_sE
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL29array_container_size_in_bytesEPKNS0_17array_container_sE
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL29array_container_size_in_bytesEPKNS0_17array_container_sE
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL29array_container_size_in_bytesEPKNS0_17array_container_sE
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL29array_container_size_in_bytesEPKNS0_17array_container_sE
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL29array_container_size_in_bytesEPKNS0_17array_container_sE
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL29array_container_size_in_bytesEPKNS0_17array_container_sE
216
217
/**
218
 * Return true if the two arrays have the same content.
219
 */
220
ALLOW_UNALIGNED
221
static inline bool array_container_equals(
222
    const array_container_t *container1,
223
0
    const array_container_t *container2) {
224
0
225
0
    if (container1->cardinality != container2->cardinality) {
226
0
        return false;
227
0
    }
228
0
    return memequals(container1->array, container2->array, container1->cardinality*2);
229
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL22array_container_equalsEPKNS0_17array_container_sES3_
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL22array_container_equalsEPKNS0_17array_container_sES3_
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL22array_container_equalsEPKNS0_17array_container_sES3_
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL22array_container_equalsEPKNS0_17array_container_sES3_
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL22array_container_equalsEPKNS0_17array_container_sES3_
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL22array_container_equalsEPKNS0_17array_container_sES3_
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL22array_container_equalsEPKNS0_17array_container_sES3_
230
231
/**
232
 * Return true if container1 is a subset of container2.
233
 */
234
bool array_container_is_subset(const array_container_t *container1,
235
                               const array_container_t *container2);
236
237
/**
238
 * If the element of given rank is in this container, supposing that the first
239
 * element has rank start_rank, then the function returns true and sets element
240
 * accordingly.
241
 * Otherwise, it returns false and update start_rank.
242
 */
243
static inline bool array_container_select(const array_container_t *container,
244
                                          uint32_t *start_rank, uint32_t rank,
245
0
                                          uint32_t *element) {
246
0
    int card = array_container_cardinality(container);
247
0
    if (*start_rank + card <= rank) {
248
0
        *start_rank += card;
249
0
        return false;
250
0
    } else {
251
0
        *element = container->array[rank - *start_rank];
252
0
        return true;
253
0
    }
254
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL22array_container_selectEPKNS0_17array_container_sEPjjS4_
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL22array_container_selectEPKNS0_17array_container_sEPjjS4_
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL22array_container_selectEPKNS0_17array_container_sEPjjS4_
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL22array_container_selectEPKNS0_17array_container_sEPjjS4_
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL22array_container_selectEPKNS0_17array_container_sEPjjS4_
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL22array_container_selectEPKNS0_17array_container_sEPjjS4_
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL22array_container_selectEPKNS0_17array_container_sEPjjS4_
255
256
/* Computes the  difference of array1 and array2 and write the result
257
 * to array out.
258
 * Array out does not need to be distinct from array_1
259
 */
260
void array_container_andnot(const array_container_t *array_1,
261
                            const array_container_t *array_2,
262
                            array_container_t *out);
263
264
/* Append x to the set. Assumes that the value is larger than any preceding
265
 * values.  */
266
static inline void array_container_append(array_container_t *arr,
267
0
                                          uint16_t pos) {
268
0
    const int32_t capacity = arr->capacity;
269
0
270
0
    if (array_container_full(arr)) {
271
0
        array_container_grow(arr, capacity + 1, true);
272
0
    }
273
0
274
0
    arr->array[arr->cardinality++] = pos;
275
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL22array_container_appendEPNS0_17array_container_sEt
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL22array_container_appendEPNS0_17array_container_sEt
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL22array_container_appendEPNS0_17array_container_sEt
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL22array_container_appendEPNS0_17array_container_sEt
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL22array_container_appendEPNS0_17array_container_sEt
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL22array_container_appendEPNS0_17array_container_sEt
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL22array_container_appendEPNS0_17array_container_sEt
276
277
/**
278
 * Add value to the set if final cardinality doesn't exceed max_cardinality.
279
 * Return code:
280
 * 1  -- value was added
281
 * 0  -- value was already present
282
 * -1 -- value was not added because cardinality would exceed max_cardinality
283
 */
284
static inline int array_container_try_add(array_container_t *arr, uint16_t value,
285
0
                                          int32_t max_cardinality) {
286
0
    const int32_t cardinality = arr->cardinality;
287
0
288
0
    // best case, we can append.
289
0
    if ((array_container_empty(arr) || arr->array[cardinality - 1] < value) &&
290
0
        cardinality < max_cardinality) {
291
0
        array_container_append(arr, value);
292
0
        return 1;
293
0
    }
294
0
295
0
    const int32_t loc = binarySearch(arr->array, cardinality, value);
296
0
297
0
    if (loc >= 0) {
298
0
        return 0;
299
0
    } else if (cardinality < max_cardinality) {
300
0
        if (array_container_full(arr)) {
301
0
            array_container_grow(arr, arr->capacity + 1, true);
302
0
        }
303
0
        const int32_t insert_idx = -loc - 1;
304
0
        memmove(arr->array + insert_idx + 1, arr->array + insert_idx,
305
0
                (cardinality - insert_idx) * sizeof(uint16_t));
306
0
        arr->array[insert_idx] = value;
307
0
        arr->cardinality++;
308
0
        return 1;
309
0
    } else {
310
0
        return -1;
311
0
    }
312
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL23array_container_try_addEPNS0_17array_container_sEti
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL23array_container_try_addEPNS0_17array_container_sEti
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL23array_container_try_addEPNS0_17array_container_sEti
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL23array_container_try_addEPNS0_17array_container_sEti
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL23array_container_try_addEPNS0_17array_container_sEti
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL23array_container_try_addEPNS0_17array_container_sEti
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL23array_container_try_addEPNS0_17array_container_sEti
313
314
/* Add value to the set. Returns true if x was not already present.  */
315
0
static inline bool array_container_add(array_container_t *arr, uint16_t value) {
316
0
    return array_container_try_add(arr, value, INT32_MAX) == 1;
317
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL19array_container_addEPNS0_17array_container_sEt
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL19array_container_addEPNS0_17array_container_sEt
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL19array_container_addEPNS0_17array_container_sEt
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL19array_container_addEPNS0_17array_container_sEt
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL19array_container_addEPNS0_17array_container_sEt
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL19array_container_addEPNS0_17array_container_sEt
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL19array_container_addEPNS0_17array_container_sEt
318
319
/* Remove x from the set. Returns true if x was present.  */
320
static inline bool array_container_remove(array_container_t *arr,
321
0
                                          uint16_t pos) {
322
0
    const int32_t idx = binarySearch(arr->array, arr->cardinality, pos);
323
0
    const bool is_present = idx >= 0;
324
0
    if (is_present) {
325
0
        memmove(arr->array + idx, arr->array + idx + 1,
326
0
                (arr->cardinality - idx - 1) * sizeof(uint16_t));
327
0
        arr->cardinality--;
328
0
    }
329
0
330
0
    return is_present;
331
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL22array_container_removeEPNS0_17array_container_sEt
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL22array_container_removeEPNS0_17array_container_sEt
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL22array_container_removeEPNS0_17array_container_sEt
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL22array_container_removeEPNS0_17array_container_sEt
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL22array_container_removeEPNS0_17array_container_sEt
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL22array_container_removeEPNS0_17array_container_sEt
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL22array_container_removeEPNS0_17array_container_sEt
332
333
/* Check whether x is present.  */
334
inline bool array_container_contains(const array_container_t *arr,
335
0
                                     uint16_t pos) {
336
0
    //    return binarySearch(arr->array, arr->cardinality, pos) >= 0;
337
0
    // binary search with fallback to linear search for short ranges
338
0
    int32_t low = 0;
339
0
    const uint16_t * carr = (const uint16_t *) arr->array;
340
0
    int32_t high = arr->cardinality - 1;
341
0
    //    while (high - low >= 0) {
342
0
    while(high >= low + 16) {
343
0
        int32_t middleIndex = (low + high)>>1;
344
0
        uint16_t middleValue = carr[middleIndex];
345
0
        if (middleValue < pos) {
346
0
            low = middleIndex + 1;
347
0
        } else if (middleValue > pos) {
348
0
            high = middleIndex - 1;
349
0
        } else {
350
0
            return true;
351
0
        }
352
0
    }
353
0
354
0
    for (int i=low; i <= high; i++) {
355
0
        uint16_t v = carr[i];
356
0
        if (v == pos) {
357
0
            return true;
358
0
        }
359
0
        if ( v > pos ) return false;
360
0
    }
361
0
    return false;
362
0
363
0
}
364
365
void array_container_offset(const array_container_t *c,
366
                            container_t **loc, container_t **hic,
367
                            uint16_t offset);
368
369
//* Check whether a range of values from range_start (included) to range_end (excluded) is present. */
370
static inline bool array_container_contains_range(const array_container_t *arr,
371
0
                                                    uint32_t range_start, uint32_t range_end) {
372
0
    const int32_t range_count = range_end - range_start;
373
0
    const uint16_t rs_included = (uint16_t)range_start;
374
0
    const uint16_t re_included = (uint16_t)(range_end - 1);
375
0
376
0
    // Empty range is always included
377
0
    if (range_count <= 0) {
378
0
        return true;
379
0
    }
380
0
    if (range_count > arr->cardinality) {
381
0
        return false;
382
0
    }
383
0
384
0
    const int32_t start = binarySearch(arr->array, arr->cardinality, rs_included);
385
0
    // If this sorted array contains all items in the range:
386
0
    // * the start item must be found
387
0
    // * the last item in range range_count must exist, and be the expected end value
388
0
    return (start >= 0) && (arr->cardinality >= start + range_count) &&
389
0
           (arr->array[start + range_count - 1] == re_included);
390
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL30array_container_contains_rangeEPKNS0_17array_container_sEjj
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL30array_container_contains_rangeEPKNS0_17array_container_sEjj
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL30array_container_contains_rangeEPKNS0_17array_container_sEjj
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL30array_container_contains_rangeEPKNS0_17array_container_sEjj
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL30array_container_contains_rangeEPKNS0_17array_container_sEjj
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL30array_container_contains_rangeEPKNS0_17array_container_sEjj
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL30array_container_contains_rangeEPKNS0_17array_container_sEjj
391
392
/* Returns the smallest value (assumes not empty) */
393
0
inline uint16_t array_container_minimum(const array_container_t *arr) {
394
0
    if (arr->cardinality == 0) return 0;
395
0
    return arr->array[0];
396
0
}
397
398
/* Returns the largest value (assumes not empty) */
399
0
inline uint16_t array_container_maximum(const array_container_t *arr) {
400
0
    if (arr->cardinality == 0) return 0;
401
0
    return arr->array[arr->cardinality - 1];
402
0
}
403
404
/* Returns the number of values equal or smaller than x */
405
0
inline int array_container_rank(const array_container_t *arr, uint16_t x) {
406
0
    const int32_t idx = binarySearch(arr->array, arr->cardinality, x);
407
0
    const bool is_present = idx >= 0;
408
0
    if (is_present) {
409
0
        return idx + 1;
410
0
    } else {
411
0
        return -idx - 1;
412
0
    }
413
0
}
414
415
/*  bulk version of array_container_rank(); return number of consumed elements */
416
inline uint32_t array_container_rank_many(const array_container_t *arr, uint64_t start_rank,
417
0
                                          const uint32_t* begin, const uint32_t* end, uint64_t* ans) {
418
0
    const uint16_t high = (uint16_t)((*begin) >> 16);
419
0
    uint32_t pos = 0;
420
0
    const uint32_t* iter = begin;
421
0
    for(; iter != end; iter++) {
422
0
        uint32_t x = *iter;
423
0
        uint16_t xhigh = (uint16_t)(x >> 16);
424
0
        if(xhigh != high) return iter - begin;// stop at next container
425
0
426
0
        const int32_t idx = binarySearch(arr->array+pos, arr->cardinality-pos, (uint16_t)x);
427
0
        const bool is_present = idx >= 0;
428
0
        if (is_present) {
429
0
            *(ans++) = start_rank + pos + (idx + 1);
430
0
            pos = idx+1;
431
0
        } else {
432
0
            *(ans++) = start_rank + pos + (-idx - 1);
433
0
        }
434
0
    }
435
0
    return iter - begin;
436
0
}
437
438
439
/* Returns the index of x , if not exsist return -1 */
440
0
inline int array_container_get_index(const array_container_t *arr, uint16_t x) {
441
0
    const int32_t idx = binarySearch(arr->array, arr->cardinality, x);
442
0
    const bool is_present = idx >= 0;
443
0
    if (is_present) {
444
0
        return idx;
445
0
    } else {
446
0
        return -1;
447
0
    }
448
0
}
449
450
/* Returns the index of the first value equal or larger than x, or -1 */
451
0
inline int array_container_index_equalorlarger(const array_container_t *arr, uint16_t x) {
452
0
    const int32_t idx = binarySearch(arr->array, arr->cardinality, x);
453
0
    const bool is_present = idx >= 0;
454
0
    if (is_present) {
455
0
        return idx;
456
0
    } else {
457
0
        int32_t candidate = - idx - 1;
458
0
        if(candidate < arr->cardinality) return candidate;
459
0
        return -1;
460
0
    }
461
0
}
462
463
/*
464
 * Adds all values in range [min,max] using hint:
465
 *   nvals_less is the number of array values less than $min
466
 *   nvals_greater is the number of array values greater than $max
467
 */
468
static inline void array_container_add_range_nvals(array_container_t *array,
469
                                                   uint32_t min, uint32_t max,
470
                                                   int32_t nvals_less,
471
0
                                                   int32_t nvals_greater) {
472
0
    int32_t union_cardinality = nvals_less + (max - min + 1) + nvals_greater;
473
0
    if (union_cardinality > array->capacity) {
474
0
        array_container_grow(array, union_cardinality, true);
475
0
    }
476
0
    memmove(&(array->array[union_cardinality - nvals_greater]),
477
0
            &(array->array[array->cardinality - nvals_greater]),
478
0
            nvals_greater * sizeof(uint16_t));
479
0
    for (uint32_t i = 0; i <= max - min; i++) {
480
0
        array->array[nvals_less + i] = (uint16_t)(min + i);
481
0
    }
482
0
    array->cardinality = union_cardinality;
483
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL31array_container_add_range_nvalsEPNS0_17array_container_sEjjii
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL31array_container_add_range_nvalsEPNS0_17array_container_sEjjii
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL31array_container_add_range_nvalsEPNS0_17array_container_sEjjii
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL31array_container_add_range_nvalsEPNS0_17array_container_sEjjii
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL31array_container_add_range_nvalsEPNS0_17array_container_sEjjii
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL31array_container_add_range_nvalsEPNS0_17array_container_sEjjii
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL31array_container_add_range_nvalsEPNS0_17array_container_sEjjii
484
485
/**
486
 * Adds all values in range [min,max]. This function is currently unused
487
 * and left as a documentation.
488
 */
489
/*static inline void array_container_add_range(array_container_t *array,
490
                                             uint32_t min, uint32_t max) {
491
    int32_t nvals_greater = count_greater(array->array, array->cardinality, max);
492
    int32_t nvals_less = count_less(array->array, array->cardinality - nvals_greater, min);
493
    array_container_add_range_nvals(array, min, max, nvals_less, nvals_greater);
494
}*/
495
496
/*
497
 * Removes all elements array[pos] .. array[pos+count-1]
498
 */
499
static inline void array_container_remove_range(array_container_t *array,
500
0
                                                uint32_t pos, uint32_t count) {
501
0
  if (count != 0) {
502
0
      memmove(&(array->array[pos]), &(array->array[pos+count]),
503
0
              (array->cardinality - pos - count) * sizeof(uint16_t));
504
0
      array->cardinality -= count;
505
0
  }
506
0
}
Unexecuted instantiation: bkd_writer.cpp:_ZN7roaring8internalL28array_container_remove_rangeEPNS0_17array_container_sEjj
Unexecuted instantiation: bkd_reader.cpp:_ZN7roaring8internalL28array_container_remove_rangeEPNS0_17array_container_sEjj
Unexecuted instantiation: packed_index_tree.cpp:_ZN7roaring8internalL28array_container_remove_rangeEPNS0_17array_container_sEjj
Unexecuted instantiation: index_tree.cpp:_ZN7roaring8internalL28array_container_remove_rangeEPNS0_17array_container_sEjj
Unexecuted instantiation: legacy_index_tree.cpp:_ZN7roaring8internalL28array_container_remove_rangeEPNS0_17array_container_sEjj
Unexecuted instantiation: docids_writer.cpp:_ZN7roaring8internalL28array_container_remove_rangeEPNS0_17array_container_sEjj
Unexecuted instantiation: IndexWriter.cpp:_ZN7roaring8internalL28array_container_remove_rangeEPNS0_17array_container_sEjj
507
508
#ifdef __cplusplus
509
} } } // extern "C" { namespace roaring { namespace internal {
510
#endif
511
512
#endif /* INCLUDE_CONTAINERS_ARRAY_H_ */