Merging Two Sorted Sequences, Attempt 2#184
Open
CTMacUser wants to merge 6 commits intoapple:mainfrom
Open
Conversation
Add top-level functions that take two sorted sequences and returns their also-sorted merger. There are eager and lazy variants.
Add test case for mergers that use a custom ordering predicate. Said predicate doesn't use all of its operands' data, so priorities on which source is used for a shared value is detectable.
Take the giant test case for the operations of the (lazy) merger sequence that don't involve the iterator, and split it into test cases for each operation separately. Use two tests for element-containment support, branching on how well the source sequences support element-containment tests.
4 tasks
Naveen-C-Ramachandrappa
approved these changes
Mar 26, 2025
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.
Description
This is an adaptation of the
std::mergefunction from the C++ language into Swift. This is the second version I've done, after [#43]. The main changes are:merge, instead of a method that extendsSequenceandLazySequenceProtocol. This necessitates a new name for the lazy version (now calledlazilyMerge), since a simple overload would prevent creating eagerly-generated mergers from lazy arguments. This is inline with other functions in this library that changed into free functions.Collectionextended support. Indexing support adds a new layer of indirection. There are two ways to handle that; either rewrite the code in theCollectionindex methods, hoping desynchronisation doesn't happen during feature changes or bug fixes, or use the same code base by generalizing it with a bigger layer of indirection. That's what the previous version did, which was hard to implement. Giving up and directing users to just call the eager version is safer.Detailed Design
The task is implemented as a set of overloaded free functions; a configuration type to reuse the algorithm for set-union, -intersection, etc.; a lazy sequence wrapper; and an iterator that contains the core code.
Documentation Plan
There is a new Guide page provided.
Test Plan
There is a new test code file provided.
Source Impact
The change is additive. It does take two names out of the global space.
Checklist