Skip to content

Conversation

@nevans
Copy link
Collaborator

@nevans nevans commented Dec 7, 2025

Returns the combined size of the ordered #entries, including any repeated numbers.

When #string is normalized, this returns the same as #cardinality. Like #cardinality, "*" is considered to be be distinct from 2Β³Β² - 1 (the maximum 32-bit unsigned integer value).

This is a breaking change. Previously, #size was an alias for #count. Now it differs in both aspects:

"*" is unique "*" is 2Β³Β² - 1
distinct set members #cardinality #count
ordered entries, including duplicates #size #count_with_duplicates

Returns the combined size of the ordered `#entries`, including any
repeated numbers.

When `#string` is normalized, this returns the same as `#cardinality`.
Like `#cardinality`, `*` is considered to be be distinct from `2Β³Β² - 1`
(the maximum 32-bit unsigned integer value).
@nevans nevans added enhancement New feature or request breaking-change Breaking change to publicly documented API labels Dec 7, 2025
@nevans nevans merged commit 497b6c7 into master Dec 7, 2025
32 checks passed
@nevans nevans deleted the sequence_set/size branch December 7, 2025 04:18
@nevans nevans added the sequence-set Any code the IMAP `sequence-set` data type or grammar rule, especially the SequenceSet class. label Dec 10, 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!
nevans added a commit that referenced this pull request Dec 17, 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Breaking change to publicly documented API 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