mixed_xor.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * mixed_xor.h
  3. *
  4. */
  5. #ifndef INCLUDE_CONTAINERS_MIXED_XOR_H_
  6. #define INCLUDE_CONTAINERS_MIXED_XOR_H_
  7. /* These functions appear to exclude cases where the
  8. * inputs have the same type and the output is guaranteed
  9. * to have the same type as the inputs. Eg, bitset unions
  10. */
  11. /*
  12. * Java implementation (as of May 2016) for array_run, run_run
  13. * and bitset_run don't do anything different for inplace.
  14. * (They are not truly in place.)
  15. */
  16. #include <roaring/containers/array.h>
  17. #include <roaring/containers/bitset.h>
  18. #include <roaring/containers/run.h>
  19. // #include "containers.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. namespace roaring {
  23. namespace internal {
  24. #endif
  25. /* Compute the xor of src_1 and src_2 and write the result to
  26. * dst (which has no container initially).
  27. * Result is true iff dst is a bitset */
  28. bool array_bitset_container_xor(const array_container_t *src_1,
  29. const bitset_container_t *src_2,
  30. container_t **dst);
  31. /* Compute the xor of src_1 and src_2 and write the result to
  32. * dst. It is allowed for src_2 to be dst. This version does not
  33. * update the cardinality of dst (it is set to BITSET_UNKNOWN_CARDINALITY).
  34. */
  35. void array_bitset_container_lazy_xor(const array_container_t *src_1,
  36. const bitset_container_t *src_2,
  37. bitset_container_t *dst);
  38. /* Compute the xor of src_1 and src_2 and write the result to
  39. * dst (which has no container initially). Return value is
  40. * "dst is a bitset"
  41. */
  42. bool bitset_bitset_container_xor(const bitset_container_t *src_1,
  43. const bitset_container_t *src_2,
  44. container_t **dst);
  45. /* Compute the xor of src_1 and src_2 and write the result to
  46. * dst. Result may be either a bitset or an array container
  47. * (returns "result is bitset"). dst does not initially have
  48. * any container, but becomes either a bitset container (return
  49. * result true) or an array container.
  50. */
  51. bool run_bitset_container_xor(const run_container_t *src_1,
  52. const bitset_container_t *src_2,
  53. container_t **dst);
  54. /* lazy xor. Dst is initialized and may be equal to src_2.
  55. * Result is left as a bitset container, even if actual
  56. * cardinality would dictate an array container.
  57. */
  58. void run_bitset_container_lazy_xor(const run_container_t *src_1,
  59. const bitset_container_t *src_2,
  60. bitset_container_t *dst);
  61. /* dst does not indicate a valid container initially. Eventually it
  62. * can become any kind of container.
  63. */
  64. int array_run_container_xor(const array_container_t *src_1,
  65. const run_container_t *src_2, container_t **dst);
  66. /* dst does not initially have a valid container. Creates either
  67. * an array or a bitset container, indicated by return code
  68. */
  69. bool array_array_container_xor(const array_container_t *src_1,
  70. const array_container_t *src_2,
  71. container_t **dst);
  72. /* dst does not initially have a valid container. Creates either
  73. * an array or a bitset container, indicated by return code.
  74. * A bitset container will not have a valid cardinality and the
  75. * container type might not be correct for the actual cardinality
  76. */
  77. bool array_array_container_lazy_xor(const array_container_t *src_1,
  78. const array_container_t *src_2,
  79. container_t **dst);
  80. /* Dst is a valid run container. (Can it be src_2? Let's say not.)
  81. * Leaves result as run container, even if other options are
  82. * smaller.
  83. */
  84. void array_run_container_lazy_xor(const array_container_t *src_1,
  85. const run_container_t *src_2,
  86. run_container_t *dst);
  87. /* dst does not indicate a valid container initially. Eventually it
  88. * can become any kind of container.
  89. */
  90. int run_run_container_xor(const run_container_t *src_1,
  91. const run_container_t *src_2, container_t **dst);
  92. /* INPLACE versions (initial implementation may not exploit all inplace
  93. * opportunities (if any...)
  94. */
  95. /* Compute the xor of src_1 and src_2 and write the result to
  96. * dst (which has no container initially). It will modify src_1
  97. * to be dst if the result is a bitset. Otherwise, it will
  98. * free src_1 and dst will be a new array container. In both
  99. * cases, the caller is responsible for deallocating dst.
  100. * Returns true iff dst is a bitset */
  101. bool bitset_array_container_ixor(bitset_container_t *src_1,
  102. const array_container_t *src_2,
  103. container_t **dst);
  104. bool bitset_bitset_container_ixor(bitset_container_t *src_1,
  105. const bitset_container_t *src_2,
  106. container_t **dst);
  107. bool array_bitset_container_ixor(array_container_t *src_1,
  108. const bitset_container_t *src_2,
  109. container_t **dst);
  110. /* Compute the xor of src_1 and src_2 and write the result to
  111. * dst. Result may be either a bitset or an array container
  112. * (returns "result is bitset"). dst does not initially have
  113. * any container, but becomes either a bitset container (return
  114. * result true) or an array container.
  115. */
  116. bool run_bitset_container_ixor(run_container_t *src_1,
  117. const bitset_container_t *src_2,
  118. container_t **dst);
  119. bool bitset_run_container_ixor(bitset_container_t *src_1,
  120. const run_container_t *src_2, container_t **dst);
  121. /* dst does not indicate a valid container initially. Eventually it
  122. * can become any kind of container.
  123. */
  124. int array_run_container_ixor(array_container_t *src_1,
  125. const run_container_t *src_2, container_t **dst);
  126. int run_array_container_ixor(run_container_t *src_1,
  127. const array_container_t *src_2, container_t **dst);
  128. bool array_array_container_ixor(array_container_t *src_1,
  129. const array_container_t *src_2,
  130. container_t **dst);
  131. int run_run_container_ixor(run_container_t *src_1, const run_container_t *src_2,
  132. container_t **dst);
  133. #ifdef __cplusplus
  134. }
  135. }
  136. } // extern "C" { namespace roaring { namespace internal {
  137. #endif
  138. #endif