Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking β€œSign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ SequenceSet ordered entries methods (backports to v0.4-stable) #402

Merged
merged 12 commits into from
Feb 7, 2025

Conversation

nevans
Copy link
Collaborator

@nevans nevans commented Feb 7, 2025 β€’

Backports all of the following PRs to v0.4-stable:

With only a few simple exceptions (relating to differences in rdoc, versioned defaults in config.rb, and the autoloads in response_data.rb) cherry-picking went smoothly and without conflicts.

This adds the following new methods to Net::IMAP::SequenceSet:

  • #count_with_duplicates: The ordered entries version of #count.
  • #count_duplicates: The difference between #count and #count_with_duplicates.
  • #has_duplicates?: Returns whether #count_duplicates is positive.
  • #each_ordered_number: The ordered entries version of #each_number.
  • #find_ordered_index: The ordered entries version of #find_index.
  • #ordered_at: The ordered entries version of #at.

nevans added 12 commits February 7, 2025 09:02
`===` is not an alias for `cover?`.  It delegates to `cover?` but
handles errors differently.
`#each_range` and `#each_number` were previously tested indirectly via
`#ranges` and `#numbers`, but this adds tests on them directly.
This splits off "normalized" vs "order preserving" methods in the
"What's here?" sections.
Adds three new SequenceSet methods for querying about "duplicates":
* `#has_duplicates?`: Returns whether the ordered entries contain any
  duplicates.
* `#count_duplicates`: Returns the count of duplicates in the ordered
  entries.
* `#count_with_duplicates`: Returns the count of numbers in the ordered
  entries, including any repeated numbers.

This is useful for adding guards to `CopyUIDData` and `UIDPlusData`, and
for getting the size of `SequenceSet#each_ordered_number` (another PR).
Less duplication, still fairly easy to read, IMO.
Yields each number in the ordered entries and returns +self+.
In `#count`, "*" is treated as if it is effectively UINT32_MAX.  That
was also the intention for `#count_with_duplicates`.

Unlike `#count`, which can assume that `*` only appears at most once,
`#count_with_duplicates` needs to check each entry.

This means that, e.g:
   SequenceSet["#{UINT32_MAX}:*"].count_with_duplicates == 1
   SequenceSet["#{UINT32_MAX},*"].count_with_duplicates == 2
This is the ordered entries version of `#find_index`.
Some of the `#[negative index]` specs were using non-negative indexes.
They've been updated to use negative indexes.

Previously, `#at` was indirectly tested only by the `SequenceSet#[]`
test and the randomized "compare to reference Set" tests.  The new tests
specifically explicitly focus on `#[]`.
This is the ordered entries variation of `#at`.
@nevans nevans added documentation Improvements or additions to documentation enhancement New feature or request backport This issue or PR is for a stable release branch labels Feb 7, 2025
@nevans nevans merged commit 6b4b143 into v0.4-stable Feb 7, 2025
30 checks passed
@nevans nevans deleted the backport-0.4-sequence_set-ordered branch February 7, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport This issue or PR is for a stable release branch documentation Improvements or additions to documentation enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

None yet

1 participant