-
-
Notifications
You must be signed in to change notification settings - Fork 748
Rename nWayUnion => multiwayMerge and NWayUnion => MultiwayMerge #5619
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ $(T2 largestPartialIntersection, | |
| $(T2 largestPartialIntersectionWeighted, | ||
| Copies out the values that occur most frequently (multiplied by | ||
| per-value weights) in a range of ranges.) | ||
| $(T2 nWayUnion, | ||
| $(T2 multiwayMerge, | ||
| Computes the union of a set of sets implemented as a range of sorted | ||
| ranges.) | ||
| $(T2 setDifference, | ||
|
|
@@ -647,7 +647,7 @@ void largestPartialIntersectionWeighted | |
| { | ||
| return weights[a[0]] * a[1] > weights[b[0]] * b[1]; | ||
| } | ||
| topNCopy!heapComp(group(nWayUnion!less(ror)), tgt, sorted); | ||
| topNCopy!heapComp(group(multiwayMerge!less(ror)), tgt, sorted); | ||
| } | ||
|
|
||
| /// | ||
|
|
@@ -744,36 +744,41 @@ void largestPartialIntersectionWeighted | |
| assert(arrayOne == arrayTwo); | ||
| } | ||
|
|
||
| // NWayUnion | ||
| // MultiwayMerge | ||
| /** | ||
| Computes the union of multiple sets. The input sets are passed as a | ||
| range of ranges and each is assumed to be sorted by $(D | ||
| less). Computation is done lazily, one union element at a time. The | ||
| complexity of one $(D popFront) operation is $(BIGOH | ||
| log(ror.length)). However, the length of $(D ror) decreases as ranges | ||
| in it are exhausted, so the complexity of a full pass through $(D | ||
| NWayUnion) is dependent on the distribution of the lengths of ranges | ||
| MultiwayMerge) is dependent on the distribution of the lengths of ranges | ||
| contained within $(D ror). If all ranges have the same length $(D n) | ||
| (worst case scenario), the complexity of a full pass through $(D | ||
| NWayUnion) is $(BIGOH n * ror.length * log(ror.length)), i.e., $(D | ||
| MultiwayMerge) is $(BIGOH n * ror.length * log(ror.length)), i.e., $(D | ||
| log(ror.length)) times worse than just spanning all ranges in | ||
| turn. The output comes sorted (unstably) by $(D less). | ||
|
|
||
| For backward compatibility, `multiwayMerge` is available under | ||
| the name `nWayUnion` and `MultiwayMerge` under the name of `NWayUnion` . | ||
| Future code should use `multiwayMerge` and `MultiwayMerge` as `nWayUnion` | ||
| and `NWayUnion` will be deprecated. | ||
|
|
||
| Params: | ||
| less = Predicate the given ranges are sorted by. | ||
| ror = A range of ranges sorted by `less` to compute the union for. | ||
|
|
||
| Returns: | ||
| A range of the union of the ranges in `ror`. | ||
|
|
||
| Warning: Because $(D NWayUnion) does not allocate extra memory, it | ||
| will leave $(D ror) modified. Namely, $(D NWayUnion) assumes ownership | ||
| Warning: Because $(D MultiwayMerge) does not allocate extra memory, it | ||
| will leave $(D ror) modified. Namely, $(D MultiwayMerge) assumes ownership | ||
| of $(D ror) and discretionarily swaps and advances elements of it. If | ||
| you want $(D ror) to preserve its contents after the call, you may | ||
| want to pass a duplicate to $(D NWayUnion) (and perhaps cache the | ||
| want to pass a duplicate to $(D MultiwayMerge) (and perhaps cache the | ||
| duplicate in between calls). | ||
| */ | ||
| struct NWayUnion(alias less, RangeOfRanges) | ||
| struct MultiwayMerge(alias less, RangeOfRanges) | ||
| { | ||
| import std.container : BinaryHeap; | ||
|
|
||
|
|
@@ -830,7 +835,7 @@ struct NWayUnion(alias less, RangeOfRanges) | |
| } | ||
|
|
||
| /// Ditto | ||
| NWayUnion!(less, RangeOfRanges) nWayUnion | ||
| MultiwayMerge!(less, RangeOfRanges) multiwayMerge | ||
| (alias less = "a < b", RangeOfRanges) | ||
| (RangeOfRanges ror) | ||
| { | ||
|
|
@@ -853,9 +858,12 @@ NWayUnion!(less, RangeOfRanges) nWayUnion | |
| auto witness = [ | ||
| 1, 1, 1, 4, 4, 7, 7, 7, 7, 8, 8 | ||
| ]; | ||
| assert(equal(nWayUnion(a), witness)); | ||
| assert(equal(multiwayMerge(a), witness)); | ||
| } | ||
|
|
||
| alias nWayUnion = multiwayMerge; | ||
| alias NWayUnion = MultiwayMerge; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah there it is |
||
|
|
||
| /** | ||
| Lazily computes the difference of $(D r1) and $(D r2). The two ranges | ||
| are assumed to be sorted by $(D less). The element types of the two | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, also please add
alias NWayUnion = NWayMergeand mention it in the doc. Forgot to mention that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
git pushplease