Skip to content

Commit c7d83bc

Browse files
committed
Check if ART is shrunken when checking if r64 is shrunken
1 parent ddfca68 commit c7d83bc

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

include/roaring/art/art.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,11 @@ bool art_iterator_erase(art_iterator_t *iterator, art_val_t *erased_val);
205205
*/
206206
size_t art_shrink_to_fit(art_t *art);
207207

208+
/**
209+
* Returns true if the ART has no unused elements.
210+
*/
211+
bool art_is_shrunken(const art_t *art);
212+
208213
/**
209214
* Returns the serialized size in bytes.
210215
* Requires `art_shrink_to_fit` to be called first.

src/art/art.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,19 +1794,6 @@ static void art_shrink_at(art_t *art, art_ref_t ref) {
17941794
}
17951795
}
17961796

1797-
static bool art_is_shrunken(const art_t *art) {
1798-
return art->first_free[CROARING_ART_LEAF_TYPE] ==
1799-
art->capacities[CROARING_ART_LEAF_TYPE] &&
1800-
art->first_free[CROARING_ART_NODE4_TYPE] ==
1801-
art->capacities[CROARING_ART_NODE4_TYPE] &&
1802-
art->first_free[CROARING_ART_NODE16_TYPE] ==
1803-
art->capacities[CROARING_ART_NODE16_TYPE] &&
1804-
art->first_free[CROARING_ART_NODE48_TYPE] ==
1805-
art->capacities[CROARING_ART_NODE48_TYPE] &&
1806-
art->first_free[CROARING_ART_NODE256_TYPE] ==
1807-
art->capacities[CROARING_ART_NODE256_TYPE];
1808-
}
1809-
18101797
void art_init_cleared(art_t *art) {
18111798
art->root = CROARING_ART_NULL_REF;
18121799
memset(art->first_free, 0, sizeof(art->first_free));
@@ -1829,6 +1816,16 @@ size_t art_shrink_to_fit(art_t *art) {
18291816
return art_shrink_node_arrays(art);
18301817
}
18311818

1819+
bool art_is_shrunken(const art_t *art) {
1820+
for (art_typecode_t t = CROARING_ART_MIN_TYPE; t <= CROARING_ART_MAX_TYPE;
1821+
++t) {
1822+
if (art->first_free[t] != art->capacities[t]) {
1823+
return false;
1824+
}
1825+
}
1826+
return true;
1827+
}
1828+
18321829
art_val_t *art_insert(art_t *art, const art_key_chunk_t *key, art_val_t val) {
18331830
art_ref_t leaf = art_leaf_create(art, key, val);
18341831
if (art->root == CROARING_ART_NULL_REF) {

src/roaring64.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ static void move_to_shrink(roaring64_bitmap_t *r, leaf_t *leaf) {
964964
}
965965

966966
static inline bool is_shrunken(const roaring64_bitmap_t *r) {
967-
return r->first_free == r->capacity;
967+
return art_is_shrunken(&r->art) && r->first_free == r->capacity;
968968
}
969969

970970
size_t roaring64_bitmap_shrink_to_fit(roaring64_bitmap_t *r) {

0 commit comments

Comments
 (0)