Skip to content

Commit

Permalink
Cleanups to roaring64
Browse files Browse the repository at this point in the history
  • Loading branch information
SLieve committed Jan 4, 2024
1 parent c38c9a0 commit a2ba114
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
1 change: 0 additions & 1 deletion include/roaring/roaring64.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ typedef struct roaring64_leaf_s roaring64_leaf_t;
*/
typedef struct roaring64_bulk_context_s {
uint8_t high_bytes[6];
uint16_t low_bytes;
roaring64_leaf_t *leaf;
} roaring64_bulk_context_t;

Expand Down
20 changes: 10 additions & 10 deletions src/roaring64.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@

#else // CROARING_IS_BIG_ENDIAN
// Gets compiled to bswap or equivalent on most compilers.
#define htobe64(x) \
(((x & 0x00000000000000FFULL) << 56) | \
((x & 0x000000000000FF00ULL) << 40) | \
((x & 0x0000000000FF0000ULL) << 24) | \
((x & 0x00000000FF000000ULL) << 8) | \
((x & 0x000000FF00000000ULL) >> 8) | \
((x & 0x0000FF0000000000ULL) >> 24) | \
((x & 0x00FF000000000000ULL) >> 40) | \
#define htobe64(x) \
(((x & 0x00000000000000FFULL) << 56) | \
((x & 0x000000000000FF00ULL) << 40) | \
((x & 0x0000000000FF0000ULL) << 24) | \
((x & 0x00000000FF000000ULL) << 8) | ((x & 0x000000FF00000000ULL) >> 8) | \
((x & 0x0000FF0000000000ULL) >> 24) | \
((x & 0x00FF000000000000ULL) >> 40) | \
((x & 0xFF00000000000000ULL) >> 56))
#endif // CROARING_IS_BIG_ENDIAN

Expand Down Expand Up @@ -278,7 +277,6 @@ void roaring64_bitmap_add_bulk(roaring64_bitmap_t *r,
// differ.
context->leaf =
containerptr_roaring64_bitmap_add(r, high48, low16, NULL);
context->low_bytes = low16;
memcpy(context->high_bytes, high48, ART_KEY_BYTES);
}
}
Expand Down Expand Up @@ -537,7 +535,6 @@ void roaring64_bitmap_remove_bulk(roaring64_bitmap_t *r,
leaf_t *leaf = (leaf_t *)art_find(art, high48);
context->leaf =
containerptr_roaring64_bitmap_remove(r, high48, low16, leaf);
context->low_bytes = low16;
memcpy(context->high_bytes, high48, ART_KEY_BYTES);
}
}
Expand Down Expand Up @@ -627,6 +624,9 @@ uint64_t roaring64_bitmap_get_cardinality(const roaring64_bitmap_t *r) {

uint64_t roaring64_bitmap_range_cardinality(const roaring64_bitmap_t *r,
uint64_t min, uint64_t max) {
if (min >= max) {
return 0;
}
max--; // A closed range is easier to work with.

uint64_t cardinality = 0;
Expand Down
1 change: 1 addition & 0 deletions tests/roaring64_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ DEFINE_TEST(test_range_cardinality) {
roaring64_bitmap_add(r, 100002);
roaring64_bitmap_add(r, 200000);

assert_true(roaring64_bitmap_range_cardinality(r, 0, 0) == 0);
assert_true(roaring64_bitmap_range_cardinality(r, 0, 100000) == 1);
assert_true(roaring64_bitmap_range_cardinality(r, 1, 100001) == 1);
assert_true(roaring64_bitmap_range_cardinality(r, 0, 200001) == 5);
Expand Down

0 comments on commit a2ba114

Please sign in to comment.