Conversation
nevans
added this pull request to stack #775
October 3, 2026 22:32
This changes a `SequenceSet#slice` to return an empty set (rather than `nil`) in the same circumstance. This mimics `Array#slice`, which returns an empty array when starting at the array's size (immediately after the last index). Note that `SequenceSet#slice` indexes the monotonic set numbers, so `#cardinality` is used instead of `#size` (which measures the ordered list data). This could be seen as a minor breaking change. But I'm treating it as a bugfix because: * `SequenceSet#slice` was always intended to mimic `Array#slice`. * The documented API doesn't change, it still returns `nil` or a set. * `SequenceSet#slice` already returns an empty set sometimes. So, I think it's unlikely there is much code that depends on this bug. And any code that _does_ depend on it is (arguably) buggy already, and should be easy to fix. Please note that this is done as a minimal change to avoid refactoring the underlying slice implementation. Since `#cardinality` isn't cached, this currently requires scanning every set element a second time, which is _very_ inefficient for large sets. Fixing `SequenceSet#slice` performance is what led to finding and fixing this bug in the first place. But, for now I'm prioritizing fixing and testing `#slice`'s behavior, even if that leads to some reduced performance in cases like this.
nevans
force-pushed
the
sequence_set/fix-slice-subset-with-invalid-start-index
branch
from
October 3, 2026 22:39
9f4aa22 to
a834715
Compare
This branch has not been deployed
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.
This changes a
SequenceSet#sliceto return an empty set (rather thannil) in the same circumstance. This mimicsArray#slice, which returns an empty array when starting at the array's size (immediately after the last index). Note thatSequenceSet#sliceindexes the monotonic set numbers, so#cardinalityis used instead of#size(which measures the ordered list data).This could be seen as a minor breaking change. But I'm treating it as a bug fix because:
SequenceSet#slicewas always intended to mimicArray#slice.nilor a set.SequenceSet#slicealready returns an empty set sometimes.So, I think it's unlikely there is much (or any) code that depends on this bug. And any code that does depend on it is (arguably) buggy already, and should be easy to fix.