Skip to content

Comments

Add documentation and unittests regarding multisets#5643

Closed
wilzbach wants to merge 1 commit intodlang:masterfrom
wilzbach:RazvanN7-Doc_setops
Closed

Add documentation and unittests regarding multisets#5643
wilzbach wants to merge 1 commit intodlang:masterfrom
wilzbach:RazvanN7-Doc_setops

Conversation

@wilzbach
Copy link
Contributor

Resubmission of #5627 due to GH's annoying hook issue (they send the wrong sha after a rebase).

@dlang-bot
Copy link
Contributor

Thanks for your pull request, @wilzbach!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

All the algorithms, except (LREF multiwayMerge) and (LREF mutiwayUnion),
are generalized to accept as input not only sets but also multisets:
$(UL
$(UI when all ranges passed as input are sets, the result is going to be
Copy link
Contributor Author

Choose a reason for hiding this comment

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

/dev/shm/dtest/work/repo/dlang.org/web/phobos-prerelease/std_algorithm_setops.html:157:<ul>    <!--UNDEFINED MACRO: "UI"-->
/dev/shm/dtest/work/repo/dlang.org/web/phobos-prerelease/std_algorithm_setops.html:158:    <!--UNDEFINED MACRO: "UI"-->

@RazvanN7 as we currently can't rebase PRs without breaking GH hooks, could you please fix this on your branch (should be LI) and resubmit a PR? Thanks!

Copy link
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

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

Getting there. Thanks!

$(LREF setIntersection), $(LREF setSymmetricDifference) expect a range of sorted
ranges as input.

All the algorithms, except (LREF multiwayMerge) and (LREF mutiwayUnion),
Copy link
Member

Choose a reason for hiding this comment

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

s/All the/All/

Since you say "all except" it's better to simple enumerate the algorithms you refer to: "The algorithms $(LREF setDifference), $(LREF setIntersection), and $(LREF setSymmetricDifference) ..."

ranges as input.

All the algorithms, except (LREF multiwayMerge) and (LREF mutiwayUnion),
are generalized to accept as input not only sets but also multisets:
Copy link
Member

Choose a reason for hiding this comment

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

Hotlink the word "multisets" to the Wikipedia article.

$(UI when all ranges passed as input are sets, the result is going to be
a set.)
$(UI if one of the ranges is a multiset, the result is going to be a multiset.)
)
Copy link
Member

Choose a reason for hiding this comment

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

This is tenuous. For example, intersecting the multiset {a, a, b} with the multiset {b, c, c} is {b} i.e. a set and not a multiset as the text above implies.

Instead of using imprecise text to then explain it, just say what happens:

"... but also multisets. Each algorithm documents behavior in the presence of duplicated inputs."

[4, 7],
[7]
];
auto y = new Tuple!(double, uint)[2];
Copy link
Member

Choose a reason for hiding this comment

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

Tuple!(double, uint)[2] y;

Copy link
Collaborator

Choose a reason for hiding this comment

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

why not auto? the rest of the examples are like this.

Copy link
Member

Choose a reason for hiding this comment

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

This works: int[10] a;
This doesn't: auto a = int[10];

Copy link
Member

Choose a reason for hiding this comment

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

note that crucially the statically sized array avoids memory allocation

$(T2 multiwayMerge,
Computes the union of a set of sets implemented as a range of sorted
ranges.)
Computes the merging of a range of sorted ranges.)
Copy link
Member

Choose a reason for hiding this comment

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

"Merging" is not a noun; it's a gerund. Therefore "computes the merging" is incorrect. The noun that would fit there is "mergence" (https://www.merriam-webster.com/dictionary/mergence) but that is used so infrequently it sure is liable to cause confusion. "Merger" is also a good fit but it's seldom used in algorithmic contexts.

Just rephrase "Computes the merge" as e.g. "Merges" everywhere.

// MultiwayMerge
/**
Computes the union of multiple sets. The input sets are passed as a
Computes the merging of multiple sets. The input sets are passed as a
Copy link
Member

Choose a reason for hiding this comment

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

Merges multiple sets.

`multiwayUnion(ror)` is functionally equivalent to `multiwayMerge(ror).uniq`.

`multiwayUnion` returns a set regardless of the type of the input ranges
(sets or multisets).
Copy link
Member

Choose a reason for hiding this comment

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

We don't distinguish sets/multisets by "type" so the sentence is misleading. Replace with:

"The output of multiwayUnion has no duplicates even when its inputs contain duplicates."


If all input ranges are sets (i.e. without duplicated elements),
the resulting range is going to be a set, otherwise the result
is going to be a multiset. In the case of multisets, the range with
Copy link
Member

Choose a reason for hiding this comment

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

No, as shown above intersecting multisets may produce a set. Just delete the first sentence in this paragraph; the second contains all needed information.

@RazvanN7
Copy link
Collaborator

Close this

@wilzbach wilzbach closed this Jul 21, 2017
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.

4 participants