X Tutup
The Wayback Machine - https://web.archive.org/web/20211018022448/https://github.com/google/guava/issues/2237
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

Multisets intersection and union: Note performance effect of argument order in javadoc #2237

Open
mpkorstanje opened this issue Nov 24, 2015 · 0 comments

Comments

@mpkorstanje
Copy link

@mpkorstanje mpkorstanje commented Nov 24, 2015

Currently Sets.intersection(Set, Set) notes that:

   * <p><b>Note:</b> The returned view performs slightly better when {@code
   * set1} is the smaller of the two sets. If you have reason to believe one of
   * your sets will generally be smaller than the other, pass it first.

My Caliper tests* show that the same is true for Multisets.intersection(Multiset, Multiset). The reverse appears to be true for Multisets.union(Multiset, Multiset), when the first argument is the larger of the two multisets it performs slightly better.

Both also logically follow from the documented iteration order of elements in the newly created multiset. However this might be worth mentioning in the java doc.

I would add the note from Sets.intersection(Set, Set) to Multisets.intersection(Multiset, Multiset) and Multisets.union(Multiset, Multiset).

*Calculating the size of the union and intersection of two HashMultisets with between 1k and 5k entries of in which the smaller set is a subset of the larger set.

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

Successfully merging a pull request may close this issue.

None yet
5 participants
X Tutup