convert.h 2.6 KB

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