Skip to content

Commit

Permalink
explicit cast uint32 to uint16; add more precise document on `rank_ma…
Browse files Browse the repository at this point in the history
…ny(begin,end,ans)`
  • Loading branch information
longqimin committed Dec 1, 2023
1 parent 8c51a45 commit c863be8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
6 changes: 3 additions & 3 deletions include/roaring/containers/array.h
Original file line number Diff line number Diff line change
Expand Up @@ -414,15 +414,15 @@ inline int array_container_rank(const array_container_t *arr, uint16_t x) {

// bulk version of array_container_rank(); return number of consumed elements
inline uint32_t array_container_rank_many(const array_container_t *arr, uint64_t start_rank, const uint32_t* begin, const uint32_t* end, uint64_t* ans){
const uint16_t high = (*begin) >> 16;
const uint16_t high = (uint16_t)((*begin) >> 16);
uint32_t pos = 0;
const uint32_t* iter = begin;
for(; iter != end; iter++) {
uint32_t x = *iter;
uint16_t xhigh = x >> 16;
uint16_t xhigh = (uint16_t)(x >> 16);
if(xhigh != high) return iter - begin;// stop at next container

const int32_t idx = binarySearch(arr->array+pos, arr->cardinality-pos, x&0xFFFF);
const int32_t idx = binarySearch(arr->array+pos, arr->cardinality-pos, (uint16_t)x);
const bool is_present = idx >= 0;
if (is_present) {
*(ans++) = start_rank + pos + (idx + 1);
Expand Down
4 changes: 3 additions & 1 deletion include/roaring/roaring.h
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,9 @@ uint64_t roaring_bitmap_rank(const roaring_bitmap_t *r, uint32_t x);
* it puts rank value of each element in `[begin .. end)` to `ans[]`
*
* the values in `[begin .. end)` must be sorted in Ascending order;
* the `ans` must have enough size.
* Caller is responsible to ensure that there is enough memory allocated, e.g.
*
* ans = malloc((end-begin) * sizeof(uint64_t));
*/
void roaring_bitmap_rank_many(const roaring_bitmap_t *r, const uint32_t* begin, const uint32_t* end, uint64_t* ans);

Expand Down
6 changes: 3 additions & 3 deletions src/containers/bitset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1233,16 +1233,16 @@ int bitset_container_rank(const bitset_container_t *container, uint16_t x) {
}

uint32_t bitset_container_rank_many(const bitset_container_t *container, uint64_t start_rank, const uint32_t* begin, const uint32_t* end, uint64_t* ans){
const uint16_t high = (*begin) >> 16;
const uint16_t high = (uint16_t)((*begin) >> 16);
int i = 0;
int sum = 0;
const uint32_t* iter = begin;
for(; iter != end; iter++) {
uint32_t x = *iter;
uint16_t xhigh = x >> 16;
uint16_t xhigh = (uint16_t)(x >> 16);
if(xhigh != high) return iter - begin; // stop at next container

uint16_t xlow = x & 0xFFFF;
uint16_t xlow = (uint16_t)x;
for(int count = xlow / 64; i < count; i++){
sum += roaring_hamming(container->words[i]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/containers/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,13 +884,13 @@ int run_container_rank(const run_container_t *container, uint16_t x) {
return sum;
}
uint32_t run_container_rank_many(const run_container_t *container, uint64_t start_rank, const uint32_t* begin, const uint32_t* end, uint64_t* ans){
const uint16_t high = (*begin) >> 16;
const uint16_t high = (uint16_t)((*begin) >> 16);
const uint32_t* iter = begin;
int sum = 0;
int i = 0;
for(;iter != end; iter++) {
uint32_t x = *iter;
uint16_t xhigh = x >> 16;
uint16_t xhigh = (uint16_t)(x >> 16);
if(xhigh != high) return iter - begin; // stop at next container

uint32_t x32 = x & 0xFFFF;
Expand Down

0 comments on commit c863be8

Please sign in to comment.