1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
#ifndef __ROARING_BUFFER_READER_H__
#define __ROARING_BUFFER_READER_H__
#include "roaring.h"
typedef struct roaring_buffer_s {
const char *buf;
size_t buf_len;
int32_t size; /* number of containers */
const uint16_t *keyscards;
const uint32_t *offsets;
const char *bitmapOfRunContainers;
bool hasrun;
bool keyscards_need_free;
bool offsets_need_free;
} roaring_buffer_t;
/**
* Creates a new roaring buffer (from a partable serialized roaringbitmap buffer).
* The caller is responsible for freeing the result.
* Returns NULL if error occurred.
*/
roaring_buffer_t *roaring_buffer_create(const char *buf, size_t buf_len);
/**
* free roaring buffer
*/
void roaring_buffer_free(const roaring_buffer_t *rb);
/**
* Get the cardinality of the bitmap (number of elements).
*/
uint64_t roaring_buffer_get_cardinality(const roaring_buffer_t *ra);
/**
* Check if value x is present
* Return false if error occurred.
*/
bool roaring_buffer_contains(const roaring_buffer_t *r,
uint32_t val,
bool *result);
/**
* Check if all the elements of ra1 are also in ra2.
* Return false if error occurred.
*/
bool roaring_buffer_is_subset(const roaring_buffer_t *ra1,
const roaring_buffer_t *ra2,
bool *result);
/**
* Computes the intersection between two bitmaps and returns new bitmap.
* The caller is responsible for freeing the result.
* Return NULL if error occurred.
*/
roaring_bitmap_t *roaring_buffer_and(const roaring_buffer_t *ra1,
const roaring_buffer_t *ra2);
/**
* Computes the size of the difference (andnot) between two bitmaps.
* The caller is responsible for freeing the result.
* Return NULL if error occurred.
*/
roaring_bitmap_t *roaring_buffer_andnot(const roaring_buffer_t *x1,
const roaring_buffer_t *x2);
/**
* Computes the size of the intersection between two bitmaps.
* Return false if error occurred.
*/
bool roaring_buffer_and_cardinality(const roaring_buffer_t *x1,
const roaring_buffer_t *x2,
uint64_t *result);
/**
* Computes the size of the union between two bitmaps.
* Return false if error occurred.
*/
bool roaring_buffer_or_cardinality(const roaring_buffer_t *x1,
const roaring_buffer_t *x2,
uint64_t *result);
/**
* Computes the size of the difference (andnot) between two bitmaps.
* Return false if error occurred.
*/
bool roaring_buffer_andnot_cardinality(const roaring_buffer_t *x1,
const roaring_buffer_t *x2,
uint64_t *result);
/**
* Computes the size of the difference (andnot) between two bitmaps.
* Return false if error occurred.
*/
bool roaring_buffer_xor_cardinality(const roaring_buffer_t *x1,
const roaring_buffer_t *x2,
uint64_t *result);
/**
* Computes the Jaccard index between two bitmaps. (Also known as the Tanimoto
* distance, or the Jaccard similarity coefficient)
*
* The Jaccard index is undefined if both bitmaps are empty.
* Return false if error occurred.
*/
bool roaring_buffer_jaccard_index(const roaring_buffer_t *x1,
const roaring_buffer_t *x2,
double *result);
/**
* Check whether two bitmaps intersect.
* Return false if error occurred.
*/
bool roaring_buffer_intersect(const roaring_buffer_t *x1,
const roaring_buffer_t *x2,
bool *result);
/**
* Returns true if the bitmap is empty (cardinality is zero).
*/
bool roaring_buffer_is_empty(const roaring_buffer_t *rb);
/**
* Check if the two bitmaps contain the same elements.
* Return false if error occurred.
*/
bool roaring_buffer_equals(const roaring_buffer_t *rb1,
const roaring_buffer_t *rb2,
bool *result);
/**
* Count the number of integers that are smaller or equal to x.
* Return false if error occurred.
*/
bool roaring_buffer_rank(const roaring_buffer_t *rb,
uint32_t x,
uint64_t *reuslt);
/**
* Get the smallest value in the set, or UINT32_MAX if the set is empty.
* Return false if error occurred.
*/
bool roaring_buffer_minimum(const roaring_buffer_t *rb,
uint32_t *result);
/**
* Get the greatest value in the set, or 0 if the set is empty.
* Return false if error occurred.
*/
bool roaring_buffer_maximum(const roaring_buffer_t *rb,
uint32_t *result);
#endif
|