mixed_intersection.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * mixed_intersection.h
  3. *
  4. */
  5. #ifndef INCLUDE_CONTAINERS_MIXED_INTERSECTION_H_
  6. #define INCLUDE_CONTAINERS_MIXED_INTERSECTION_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, array intersection
  10. */
  11. #include <roaring/containers/array.h>
  12. #include <roaring/containers/bitset.h>
  13. #include <roaring/containers/run.h>
  14. #ifdef __cplusplus
  15. extern "C" {
  16. namespace roaring {
  17. namespace internal {
  18. #endif
  19. /* Compute the intersection of src_1 and src_2 and write the result to
  20. * dst. It is allowed for dst to be equal to src_1. We assume that dst is a
  21. * valid container. */
  22. void array_bitset_container_intersection(const array_container_t *src_1,
  23. const bitset_container_t *src_2,
  24. array_container_t *dst);
  25. /* Compute the size of the intersection of src_1 and src_2. */
  26. int array_bitset_container_intersection_cardinality(
  27. const array_container_t *src_1, const bitset_container_t *src_2);
  28. /* Checking whether src_1 and src_2 intersect. */
  29. bool array_bitset_container_intersect(const array_container_t *src_1,
  30. const bitset_container_t *src_2);
  31. /*
  32. * Compute the intersection between src_1 and src_2 and write the result
  33. * to *dst. If the return function is true, the result is a bitset_container_t
  34. * otherwise is a array_container_t. We assume that dst is not pre-allocated. In
  35. * case of failure, *dst will be NULL.
  36. */
  37. bool bitset_bitset_container_intersection(const bitset_container_t *src_1,
  38. const bitset_container_t *src_2,
  39. container_t **dst);
  40. /* Compute the intersection between src_1 and src_2 and write the result to
  41. * dst. It is allowed for dst to be equal to src_1. We assume that dst is a
  42. * valid container. */
  43. void array_run_container_intersection(const array_container_t *src_1,
  44. const run_container_t *src_2,
  45. array_container_t *dst);
  46. /* Compute the intersection between src_1 and src_2 and write the result to
  47. * *dst. If the result is true then the result is a bitset_container_t
  48. * otherwise is a array_container_t.
  49. * If *dst == src_2, then an in-place intersection is attempted
  50. **/
  51. bool run_bitset_container_intersection(const run_container_t *src_1,
  52. const bitset_container_t *src_2,
  53. container_t **dst);
  54. /* Compute the size of the intersection between src_1 and src_2 . */
  55. int array_run_container_intersection_cardinality(const array_container_t *src_1,
  56. const run_container_t *src_2);
  57. /* Compute the size of the intersection between src_1 and src_2
  58. **/
  59. int run_bitset_container_intersection_cardinality(
  60. const run_container_t *src_1, const bitset_container_t *src_2);
  61. /* Check that src_1 and src_2 intersect. */
  62. bool array_run_container_intersect(const array_container_t *src_1,
  63. const run_container_t *src_2);
  64. /* Check that src_1 and src_2 intersect.
  65. **/
  66. bool run_bitset_container_intersect(const run_container_t *src_1,
  67. const bitset_container_t *src_2);
  68. /*
  69. * Same as bitset_bitset_container_intersection except that if the output is to
  70. * be a
  71. * bitset_container_t, then src_1 is modified and no allocation is made.
  72. * If the output is to be an array_container_t, then caller is responsible
  73. * to free the container.
  74. * In all cases, the result is in *dst.
  75. */
  76. bool bitset_bitset_container_intersection_inplace(
  77. bitset_container_t *src_1, const bitset_container_t *src_2,
  78. container_t **dst);
  79. #ifdef __cplusplus
  80. }
  81. }
  82. } // extern "C" { namespace roaring { namespace internal {
  83. #endif
  84. #endif /* INCLUDE_CONTAINERS_MIXED_INTERSECTION_H_ */