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

Merging Sorted Sequences #43

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Merging Sorted Sequences #43

wants to merge 9 commits into from

Conversation

CTMacUser
Copy link
Contributor

This library adapts the C++ algorithm functions that take two sorted sequences and returns an also-sorted sequence that represents the set-difference, intersection, union, etc.. Instead of separate functions for each operation, the desired operation is selected by an enumeration value. (All the operations follow the same algorithm.) This includes an operation to do the general merge sort!

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

Add a type describing the subsets that can be taken of the merger of two sets.

Add a type that is a sequence that takes two sequences, a predicate that both sources are sorted along, and a merger-subset state, and vends the seleected subset of the merger which is also sorted.  Add an extension method to sequences that takes another sequence, ordering predicate, and subset selection and returns an array with the merged sequence.  Add lazy variants of this method.  Add overloads that default the ordering predicate to the standard less-than operator.
Implement the property that underreports the element count, built by combining the sources' counts.  Implement the method that briefly gives access to the elements' buffer, non-NIL only when at most one source sequence needs to be used.  Implement the secret method that optimizes the element-containment test, built by combining the sources' search results.
Add a test that will go through all of the code paths of the eager method to merge sorted sequences.
Replace the two private methods used to implement the throwing version of element iteration (for the iterator type) with a single private method that returns both sources' elements for a corresponding pair, using a custom return type.  It's not only simpler, but should help in implementing merged sorted collections.
Remove a "which-one" flag from a case of an internal accounting enumeration type. It was never actually used.
Augment the type used to present the sorted merger of two sorted sequences to conditionally conform to Collection when both sources are also collections.  This involves new types to represent Index, Indices, and Indices.Iterator.  Like the eager merger algorithm, it reuses the lazy iteration code.
Add test to merge sorted sequences with a custom predicate that is not the standard less-than operator.  This predicate does not use all of the operands' members, so the source of a particular element can be tested.
@@ -0,0 +1,125 @@
# Permutations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Permutations
# MergeSorted

@CTMacUser
Copy link
Contributor Author

This is now obsolete from my next attempt at [#184].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants