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

fix setdiff(::IntSet, x) when x <= 0 #23191

Merged
merged 1 commit into from
Aug 9, 2017
Merged

Conversation

rfourquet
Copy link
Member

No description provided.

@rfourquet rfourquet added bugfix This change fixes an existing bug collections Data structures holding multiple items, e.g. sets labels Aug 9, 2017
@@ -143,7 +143,7 @@ function intersect!(s1::IntSet, s2::IntSet)
end

setdiff(s::IntSet, ns) = setdiff!(copy(s), ns)
setdiff!(s::IntSet, ns) = (for n in ns; _delete!(s, n); end; s)
setdiff!(s::IntSet, ns) = (for n in ns; delete!(s, n); end; s)
Copy link
Member

Choose a reason for hiding this comment

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

IIUC, the cost of this change is an additional branch for each element in ns?

Copy link
Member

Choose a reason for hiding this comment

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

Yes I think so, but it seems unavoidable since there's no way to know that everything in ns is safe in general.

Copy link
Member

Choose a reason for hiding this comment

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

Perhaps some construct with an @boundscheck could provide an escape hatch?

Copy link
Member Author

Choose a reason for hiding this comment

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

At least the optimized method (below) when ns is an IntSet remains unaffected. It would also be easy to have an unsafe_setdiff! if needed (till now, it seems @boundscheck is not used for this kind of usage?)

@JeffBezanson JeffBezanson merged commit cdb660c into master Aug 9, 2017
@JeffBezanson JeffBezanson deleted the rf/fix-intset-setdiff branch August 9, 2017 19:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug collections Data structures holding multiple items, e.g. sets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants