1/*
2 * convert.h
3 *
4 */
5
6#ifndef INCLUDE_CONTAINERS_CONVERT_H_
7#define INCLUDE_CONTAINERS_CONVERT_H_
8
9#include <roaring/containers/array.h>
10#include <roaring/containers/bitset.h>
11#include <roaring/containers/run.h>
12
13/* Convert an array into a bitset. The input container is not freed or modified.
14 */
15bitset_container_t *bitset_container_from_array(const array_container_t *arr);
16
17/* Convert a run into a bitset. The input container is not freed or modified. */
18bitset_container_t *bitset_container_from_run(const run_container_t *arr);
19
20/* Convert a run into an array. The input container is not freed or modified. */
21array_container_t *array_container_from_run(const run_container_t *arr);
22
23/* Convert a bitset into an array. The input container is not freed or modified.
24 */
25array_container_t *array_container_from_bitset(const bitset_container_t *bits);
26
27/* Convert an array into a run. The input container is not freed or modified.
28 */
29run_container_t *run_container_from_array(const array_container_t *c);
30
31/* convert a run into either an array or a bitset
32 * might free the container */
33void *convert_to_bitset_or_array_container(run_container_t *r, int32_t card,
34 uint8_t *resulttype);
35
36/* convert containers to and from runcontainers, as is most space efficient.
37 * The container might be freed. */
38void *convert_run_optimize(void *c, uint8_t typecode_original,
39 uint8_t *typecode_after);
40
41/* converts a run container to either an array or a bitset, IF it saves space.
42 */
43/* If a conversion occurs, the caller is responsible to free the original
44 * container and
45 * he becomes reponsible to free the new one. */
46void *convert_run_to_efficient_container(run_container_t *c,
47 uint8_t *typecode_after);
48// like convert_run_to_efficient_container but frees the old result if needed
49void *convert_run_to_efficient_container_and_free(run_container_t *c,
50 uint8_t *typecode_after);
51
52/**
53 * Create new bitset container which is a union of run container and
54 * range [min, max]. Caller is responsible for freeing run container.
55 */
56bitset_container_t *bitset_container_from_run_range(const run_container_t *run,
57 uint32_t min, uint32_t max);
58
59#endif /* INCLUDE_CONTAINERS_CONVERT_H_ */
60