mixed_negation.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * mixed_negation.h
  3. *
  4. */
  5. #ifndef INCLUDE_CONTAINERS_MIXED_NEGATION_H_
  6. #define INCLUDE_CONTAINERS_MIXED_NEGATION_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. /* Negation across the entire range of the container.
  16. * Compute the negation of src and write the result
  17. * to *dst. The complement of a
  18. * sufficiently sparse set will always be dense and a hence a bitmap
  19. * We assume that dst is pre-allocated and a valid bitset container
  20. * There can be no in-place version.
  21. */
  22. void array_container_negation(const array_container_t *src,
  23. bitset_container_t *dst);
  24. /* Negation across the entire range of the container
  25. * Compute the negation of src and write the result
  26. * to *dst. A true return value indicates a bitset result,
  27. * otherwise the result is an array container.
  28. * We assume that dst is not pre-allocated. In
  29. * case of failure, *dst will be NULL.
  30. */
  31. bool bitset_container_negation(const bitset_container_t *src,
  32. container_t **dst);
  33. /* inplace version */
  34. /*
  35. * Same as bitset_container_negation except that if the output is to
  36. * be a
  37. * bitset_container_t, then src is modified and no allocation is made.
  38. * If the output is to be an array_container_t, then caller is responsible
  39. * to free the container.
  40. * In all cases, the result is in *dst.
  41. */
  42. bool bitset_container_negation_inplace(bitset_container_t *src,
  43. container_t **dst);
  44. /* Negation across the entire range of container
  45. * Compute the negation of src and write the result
  46. * to *dst.
  47. * Return values are the *_TYPECODES as defined * in containers.h
  48. * We assume that dst is not pre-allocated. In
  49. * case of failure, *dst will be NULL.
  50. */
  51. int run_container_negation(const run_container_t *src, container_t **dst);
  52. /*
  53. * Same as run_container_negation except that if the output is to
  54. * be a
  55. * run_container_t, and has the capacity to hold the result,
  56. * then src is modified and no allocation is made.
  57. * In all cases, the result is in *dst.
  58. */
  59. int run_container_negation_inplace(run_container_t *src, container_t **dst);
  60. /* Negation across a range of the container.
  61. * Compute the negation of src and write the result
  62. * to *dst. Returns true if the result is a bitset container
  63. * and false for an array container. *dst is not preallocated.
  64. */
  65. bool array_container_negation_range(const array_container_t *src,
  66. const int range_start, const int range_end,
  67. container_t **dst);
  68. /* Even when the result would fit, it is unclear how to make an
  69. * inplace version without inefficient copying. Thus this routine
  70. * may be a wrapper for the non-in-place version
  71. */
  72. bool array_container_negation_range_inplace(array_container_t *src,
  73. const int range_start,
  74. const int range_end,
  75. container_t **dst);
  76. /* Negation across a range of the container
  77. * Compute the negation of src and write the result
  78. * to *dst. A true return value indicates a bitset result,
  79. * otherwise the result is an array container.
  80. * We assume that dst is not pre-allocated. In
  81. * case of failure, *dst will be NULL.
  82. */
  83. bool bitset_container_negation_range(const bitset_container_t *src,
  84. const int range_start, const int range_end,
  85. container_t **dst);
  86. /* inplace version */
  87. /*
  88. * Same as bitset_container_negation except that if the output is to
  89. * be a
  90. * bitset_container_t, then src is modified and no allocation is made.
  91. * If the output is to be an array_container_t, then caller is responsible
  92. * to free the container.
  93. * In all cases, the result is in *dst.
  94. */
  95. bool bitset_container_negation_range_inplace(bitset_container_t *src,
  96. const int range_start,
  97. const int range_end,
  98. container_t **dst);
  99. /* Negation across a range of container
  100. * Compute the negation of src and write the result
  101. * to *dst. Return values are the *_TYPECODES as defined * in containers.h
  102. * We assume that dst is not pre-allocated. In
  103. * case of failure, *dst will be NULL.
  104. */
  105. int run_container_negation_range(const run_container_t *src,
  106. const int range_start, const int range_end,
  107. container_t **dst);
  108. /*
  109. * Same as run_container_negation except that if the output is to
  110. * be a
  111. * run_container_t, and has the capacity to hold the result,
  112. * then src is modified and no allocation is made.
  113. * In all cases, the result is in *dst.
  114. */
  115. int run_container_negation_range_inplace(run_container_t *src,
  116. const int range_start,
  117. const int range_end,
  118. container_t **dst);
  119. #ifdef __cplusplus
  120. }
  121. }
  122. } // extern "C" { namespace roaring { namespace internal {
  123. #endif
  124. #endif /* INCLUDE_CONTAINERS_MIXED_NEGATION_H_ */