Repository navigation
Add BITRANGEINTARRAY for native bitmap enumeration - #15986
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## unstable #15986 +/- ##
============================================
+ Coverage 77.73% 78.08% +0.35%
============================================
Files 157 157
Lines 93128 93257 +129
============================================
+ Hits 72393 72820 +427
+ Misses 20735 20437 -298
🚀 New features to boost your workflow:
|
|
32-bit runtime validation now passes: 35 feature tests and 508 RESP2/RESP3 checks, including the new string-read path. Tested |
BITRANGEINTARRAY key bit start end [BYTE|BIT] [LIMIT count] As in BITPOS, the bit argument (0 or 1) selects which bits are returned. Unlike BITPOS, the range never extends past the end of the value, so no clear bits are returned beyond it. Strings invert each word when looking for clear bits. The scan is always inlined with a constant bit, so looking for set bits keeps the plain loop. Native bitmaps return clear bits as the gaps between runs of set bits, so long runs are skipped at once. Both native walks read and pass offsets in batches that start at 16 and double up to 256, so short ranges and small LIMITs read little past what they return. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The string/native parity and BYTE LIMIT tests derive NOT keys with BITOP, whose source and destination must be in the same slot in cluster mode. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 2b8ab5f. Configure here.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The name no longer reads like the BIT unit keyword that can follow the range, and matches the 0 or 1 argument of SETBIT. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Could a maintainer add |
BITRANGEINTARRAY key start end [BIT|BYTE] [LIMIT count] [ZEROS] returns the set bits by default, and the clear bits with ZEROS. The common case no longer needs a 0 or 1 argument that reads like the BIT unit keyword. Co-Authored-By: Claude Opus 5.5 <[email protected]>
added |
Add BITRANGEINTARRAY from redis/redis#15986. Co-authored-by: Claude Sonnet 5.5 <[email protected]>

Bitmap enumeration
Adds
BITRANGEINTARRAY key start end [BYTE|BIT] [LIMIT count] [ZEROS], which returns the offsets of the set bits in a range, or of the clear bits withZEROS, as an ascending integer array. Offsets are numbered as inGETBIT/SETBIT: bit 0 is the most significant bit of the first byte.Command behavior
bitmap-default-roaringsetting. Strings are read in place, so their bytes, type and expiration are unchanged.startandendare required and followBITCOUNTrange semantics: inclusive,BYTEby default orBIT, negative indexes count from the end, out-of-range ends are clamped, and a reversed range is empty. WithoutLIMIT, the reply length equalsBITCOUNT key start end [unit]for set bits; withZEROSit is the number of bits in the range minus that count.0 -1covers the whole value.ZEROSreturns the clear bits instead of the set bits. The range never extends past the end of the value: unlikeBITPOS key 0, which reports the first bit past the end of an all-ones value,ZEROSreturns only clear bits inside the value.LIMIT countreturns the lowestcountoffsets in the range and stops the scan once they are found.LIMIT 0returns an empty array and a negative count is an error. To page:BIT: the reply stops atcount; pass the last returned offset + 1 as the nextstart. A reply with fewer thancountoffsets ends the scan.BYTE: the reply also completes the byte holding the last offset, so it can hold up to 7 more; pass that byte + 1 (last offset / 8 + 1) as the nextstart. For an unchanged value, pages never repeat or skip offsets. Separate calls do not share a snapshot.BYTE/BIT,LIMITandZEROSfollow the range in any order. A repeated option takes its last value.WRONGTYPE. There is no fixed result-count cap; client output-buffer limits still apply.Implementation
bitroarVisitBitsseeks to the start of the range, without a cardinality scan.ZEROS, the runs of set bits are read and the gaps between them returned, so long runs are skipped at once.bitrangeintarrayStringscans 64-bit words in place, skips words without a matching bit, and visits only matching bits withclz, inverting each word forZEROS. No temporary bitmap is allocated.normalizeBitRangeaccepts NULL byte masks for callers that only need the bit interval.Documentation
redis/docs#4304 documents the command.
Note
Medium Risk
New public read path can emit very large replies and is bounded only by client output-buffer limits; core bitmap range semantics were extended via nullable masks in shared helpers.
Overview
Adds the read-only
BITRANGEINTARRAYcommand (8.12.0), which returns ascending bit offsets for set bits in a range—or clear bits withZEROS—usingBITCOUNT-stylestart/end, optionalBYTE/BIT,LIMIT, and BYTE-unit paging that finishes the last byte so clients can page without gaps.Native bitmaps enumerate via new
bitroarVisitBits(Roaring iterator batches of 256;ZEROSwalks gaps between set runs). String values use an in-place 64-bit word scan withclz, without building a temporary bitmap. Replies stream into a deferred-length array (no result-sized allocation) and stop when client output limits schedule disconnect.normalizeBitRangenow allows NULL byte masks when only the bit interval is needed.Command metadata lands in
commands.def/bitrangeintarray.json, with broadbitroar.tclcoverage and atools/bitroar-intarray-bench.pyharness comparing native vs module int-array reads.Reviewed by Cursor Bugbot for commit 88147bd. Bugbot is set up for automated code reviews on this repo. Configure here.