Upgrade to CRoaring 5.1.0 and complete the 32-bit and 64-bit API - #28
Merged
Conversation
Replaces the vendored amalgamation with v5.0.0 (was 4.5.0). No API was removed upstream; 5.0 adds the iterator range reads and, in 64 bits, add_offset/sub_offset, contains_range_closed, overwrite and remove_run_compression. Adds Roaring64Bitmap, which had no Swift coverage at all. It mirrors RoaringBitmap over UInt64 -- Sequence, Equatable, Hashable, ExpressibleByArrayLiteral, SetAlgebra, Codable, the same operators and range sugar -- and covers 86 of the 88 public roaring64_* functions. It bridges both ways with the 32-bit type: init(moving:) steals the containers and leaves the source empty, as the C does, while init(_:) copies. Fills in the 32-bit gaps: bulk contexts, addOffset, closed-range contains/cardinality/flip, intersectWithRange, rankMany, index(of:), copy-on-write, closure iteration, toBitsetWords, deserializeSafe, frozen serialization and views, portableDeserializeFrozen, internalValidate, paged toArray(offset:limit:), and eleven iterator operations. The overwrite, removeMany and toArrayRange stubs that were commented out are now implemented. Frozen views need their buffer to outlive the bitmap, so both classes own an aligned copy (32 bytes for 32-bit, 64 for 64-bit) released in deinit. select(rank:value:) copied its value argument and discarded the result, so it could never return the selected element. Adds select(rank:) -> UInt32? and deprecates the old spelling rather than removing it. 190 of the 198 public C functions are now called directly. The rest are accounted for in the class documentation: the two variadic _from macros, the two init functions for caller-allocated bitmaps, the heap-allocated iterator trio replaced by the allocation-free value type, and add_offset_signed reached through addOffset/subtractOffset. 87 tests pass, clean under AddressSanitizer and with no leaks. Claude-Session: https://claude.ai/code/session_01QMuwjcdsRtfysUvwPUWra9
The same information lives in the doc comments on RoaringBitmap and Roaring64Bitmap, where it stays next to the code it describes. Claude-Session: https://claude.ai/code/session_01QMuwjcdsRtfysUvwPUWra9
Nothing was removed from the public API. 5.1 adds one function, roaring64_bitmap_portable_deserialize_frozen, the 64-bit counterpart of the 32-bit one: a read-only view whose container payloads alias the buffer instead of being copied. It is bounded by maxbytes, unlike the 32-bit version, and returns NULL on big-endian machines. Wraps it as portableDeserializeFrozen(bytes:), reusing the owned-copy pattern that keeps the backing buffer alive for as long as the view. The allocation in frozenView(bytes:) moves into a shared withOwnedAlignedCopy helper, mirroring the 32-bit file. 191 of the 199 public C functions are now called directly; the eight exclusions are unchanged. 88 tests pass, clean under AddressSanitizer. Claude-Session: https://claude.ai/code/session_01QMuwjcdsRtfysUvwPUWra9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upgrades the vendored CRoaring amalgamation to v5.1.0 and completes the Swift API so that it covers CRoaring's public C functions in both 32 and 64 bits.
CRoaring 4.5.0 → 5.1.0
Sources/CRoaring/roaring.{c,h}replaced with the v5.1.0 release assets. Nothing was removed from the public API across either step.*_read_ranges,*_read_prev_ranges,*_read_backward) and, on the 64-bit side,add_offset/sub_offset,contains_range_closed,overwrite,remove_run_compression.roaring64_bitmap_portable_deserialize_frozen, the 64-bit counterpart of the 32-bit one: a read-only view whose container payloads alias the buffer instead of being copied. Unlike the 32-bit version it is bounded bymaxbytes, and it returns NULL on big-endian machines.New
Roaring64BitmapThe 64-bit API had no Swift coverage at all. The new final class mirrors
RoaringBitmapoverUInt64—Sequence,Equatable,Hashable,ExpressibleByArrayLiteral,SetAlgebra,Codable, the same operators and range sugar — and covers 87 of the 89 publicroaring64_*functions: bulk contexts, offsets, rank/select/index, statistics, validation, portable and frozen serialization, and a full iterator (forward/backward, seek, block reads, run reads).It bridges both ways with the 32-bit type:
init(moving:)steals the containers and leaves the source empty, exactly as the C does, whileinit(_:)copies.Completed 32-bit API
Added bulk contexts,
addOffset, closed-range variants of contains/cardinality/flip,intersectWithRange,rankMany,index(of:), copy-on-write (copyOnWrite,containsShared,unshareAll), closure iteration (iterate,iterate64),toBitsetWords,deserializeSafe, frozen serialization and views,portableDeserializeFrozen,internalValidate, pagedtoArray(offset:limit:), and eleven iterator operations. Theoverwrite,removeManyandtoArrayRangestubs that had been left commented out are now implemented.Frozen views require their backing buffer to outlive the bitmap, so both classes own an aligned copy (32-byte for 32-bit, 64-byte for 64-bit) released in
deinit.One API fix
select(rank:value:) -> Boolcopied itsvalueargument into a local and threw the result away, so it could never return the selected element. This addsselect(rank:) -> UInt32?and marks the old spelling deprecated rather than removing it. The one test that used it is updated.Coverage
191 of the 199 public C functions are called directly. The remaining eight are accounted for, and documented in the class doc comments:
roaring_bitmap_from,roaring64_bitmap_frominit(values:)/ array literalsroaring_bitmap_init_with_capacity,roaring_bitmap_init_clearedroaring_bitmap_t→init()/init(capacity:)roaring_iterator_create,roaring_uint32_iterator_copy,roaring_uint32_iterator_freeRoaringBitmapIteratoris an allocation-free value type, and copying the struct copies the positionroaring64_bitmap_add_offset_signedaddOffset(_:)andsubtractOffset(_:)Verification
88 tests pass (33 existing, 55 new), clean under AddressSanitizer, no leaks attributable to SwiftRoaring, and no compiler warnings. The README's 64-bit example was compiled and run — its printed values are real output. The README's existing
bitmap && cpytypo is also fixed (the operator is&).https://claude.ai/code/session_01QMuwjcdsRtfysUvwPUWra9