Skip to content

Conversation

@nevans
Copy link
Collaborator

@nevans nevans commented Dec 6, 2025

Unlike #count, #cardinality handles * the way you would expect a set to handle it, as its own distinct member.

@nevans nevans force-pushed the sequence_set/cardinality branch from bbdda34 to ac4699f Compare December 6, 2025 18:57
Unlike `#count`, `#cardinality` handles `*` in a more conventional way,
as its own distinct member.
@nevans nevans force-pushed the sequence_set/cardinality branch from ac4699f to 378b607 Compare December 7, 2025 03:39
@nevans nevans merged commit c4a243b into master Dec 7, 2025
32 checks passed
@nevans nevans deleted the sequence_set/cardinality branch December 7, 2025 03:44
@nevans nevans added enhancement New feature or request sequence-set Any code the IMAP `sequence-set` data type or grammar rule, especially the SequenceSet class. labels Dec 7, 2025
nevans added a commit that referenced this pull request Dec 16, 2025
When `SequenceSet#max(n)` is called with `n > cardinality`, it _should_
return a duplicate of the whole set.  But, `#max(n)` is implemented
using `#slice(-n..)`, and (copying the behavior of `Array`), when a
slicing starts from an out-of-range index, it returns `nil`.

It was using `-[count, size].min` to keep the index from going
out-of-range.  Prior to #564, `#size` was the same as `#count`, so it
would give incorrect results when the set contains an endless range.
After #564, this gives incorrect results when the ordered list contains
duplicates.

This change should also give a small performance boost, because it
bypasses the complexity of `#slice(range)` and just calls `#dup` (or
returns `self` when the set is frozen).

This issue was one of the motivations for #563 (and #564), but then I
forgot about the bug, so it wasn't fixed in time for 0.6.0!
nevans added a commit that referenced this pull request Dec 16, 2025
When `SequenceSet#max(n)` is called with `n > cardinality`, it _should_
return a duplicate of the whole set.  But, `#max(n)` is implemented
using `#slice(-n..)`, and (copying the behavior of `Array`), when a
slicing starts from an out-of-range index, it returns `nil`.

It was using `-[count, size].min` to keep the index from going
out-of-range.  Prior to #564, `#size` was the same as `#count`, so it
would give incorrect results when the set contains an endless range.
After #564, this gives incorrect results when the ordered list contains
duplicates.

This change should also give a small performance boost, because it
bypasses the complexity of `#slice(range)` and just calls `#dup` (or
returns `self` when the set is frozen).

This issue was one of the motivations for #563 (and #564), but then I
forgot about the bug, so it wasn't fixed in time for 0.6.0!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request sequence-set Any code the IMAP `sequence-set` data type or grammar rule, especially the SequenceSet class.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants