Skip to content

feat: Add roaring feature with GetSize impls for RoaringBitmap and RoaringTreemap#49

Merged
bircni merged 5 commits into
bircni:mainfrom
AlJohri:roaring-rs
Jun 5, 2026
Merged

feat: Add roaring feature with GetSize impls for RoaringBitmap and RoaringTreemap#49
bircni merged 5 commits into
bircni:mainfrom
AlJohri:roaring-rs

Conversation

@AlJohri

@AlJohri AlJohri commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a roaring feature with GetSize impls for roaring::RoaringBitmap and roaring::RoaringTreemap, following the established pattern from the dashmap/half/parking_lot features (#46, #47, #48).

Implementation

  • RoaringBitmap: sums statistics().n_bytes_{array,bitset,run}_containers. The Statistics API already walks every container internally and reports per-flavor byte totals (capacity()-based for array and run, fixed 8 KiB for bitset), so no internal access to private container types is needed.
    • Not counted (both small relative to container contents and documented at the impl): the outer Vec<Container> slot allocation (Container is pub(crate), so its size isn't accessible from outside the crate) and per-container tag/key fields.
  • RoaringTreemap: internally a BTreeMap<u32, RoaringBitmap>. The map is private but the bitmaps() method exposes a public iterator over (u32, &RoaringBitmap). Mirrors the existing BTreeMap<K, V> impl in collections.rs — per-entry adds stack-size + heap-size of both key and value, doesn't attempt to account for BTreeMap node padding.

Tests

  • test_roaring_bitmap: empty, array container, bitset container, run container (via optimize()), tracker-variant path.
  • test_roaring_treemap: empty, two-partition treemap matching the sum of contained bitmaps, tracker-variant path.

Notes

  • Feature name roaring matches the published crate name on crates.io (the -rs is only in the GitHub repo name, same convention as parking_lot whose repo is Amanieu/parking_lot).
  • default-features = false on the dep to preserve no_std-compatibility for downstream users.

AlJohri added 3 commits May 29, 2026 14:09
- Add debug_assert on the u64→usize cast so an upstream invariant
  breach surfaces in debug while still saturating in release.
- Tighten test assertions to compare exactly against the sum of all
  three container-flavor totals, catching a dropped flavor.
- Exercise non-trivial per-bitmap heap size in the treemap test.
- Trim comments to WHY-only and unify the tracker type-param name.
@AlJohri AlJohri marked this pull request as ready for review June 5, 2026 17:54
@bircni

bircni commented Jun 5, 2026

Copy link
Copy Markdown
Owner

fucked up the merge xD

@bircni bircni merged commit 6b411c1 into bircni:main Jun 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants