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 Issue 16996 - std.algorithm.remove with SwapStrategy.unstable rem… #4979

Merged
merged 3 commits into from
Dec 29, 2016

Conversation

WalterWaldron
Copy link
Contributor

@WalterWaldron WalterWaldron commented Dec 21, 2016

…oves more entries

https://issues.dlang.org/show_bug.cgi?id=16996
#4973 (comment)

Note: since I renamed the steps variable, the split diff view is recommended.

@dlang-bot
Copy link
Contributor

Fix Bugzilla Description
16996 std.algorithm.remove with SwapStrategy.unstable removes more entries

Copy link
Member

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

Nice. Thanks a lot for the quick fix!
This LGTM, but given that I accidentally found this while adding trying to find simple public examples, how about adding a couple of internal tests to ensure everything is working fine?
Maybe with the famous DummyRange (there's also a "potential buggy" remove specialization for only bidirectional ranges).

Last but not least it would be great if you could annotate a unittest block with @nogc, s.t. we ensure that at least the unstable SwappingStrategy doesn't allocate.

@WalterWaldron
Copy link
Contributor Author

WalterWaldron commented Dec 21, 2016

This LGTM, but given that I accidentally found this while adding trying to find simple public examples, how about adding a couple of internal tests to ensure everything is working fine?

Ok, I'll add more thorough unit testing for both stable and unstable remove.

@WalterWaldron
Copy link
Contributor Author

WalterWaldron commented Dec 22, 2016

there's also a "potential buggy" remove specialization for only bidirectional ranges

I've added a rather extreme unittest which tests both stable and unstable versions of both predicate and index based remove, and after this fix all remove functions seem consistent.

Last but not least it would be great if you could annotate a unittest block with @nogc, s.t. we ensure that at least the unstable SwappingStrategy doesn't allocate.

Swapping strategy does not affect whether it allocates, so I included every function in the annotated unittest block.

if (i < prev)
return false;
prev = i;
}
Copy link
Member

Choose a reason for hiding this comment

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

foreach (i; r)
foreach (offset; offsets)
if (i >= offset[0] && i < offset[1])
return false;
Copy link
Member

@wilzbach wilzbach Dec 29, 2016

Choose a reason for hiding this comment

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

If you want to avoid the "red", uncovered line you could do sth. like:

import std.algorithm.searching : any, canFind;
import std.range : only;
return r.any!(e => !offsets.only.canFind!(o => o[0] <= e && e < o[1]));

r = r.remove!(pred, SwapStrategy.stable);
}

unittest
Copy link
Member

Choose a reason for hiding this comment

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

FYI: (not important for now) in the near future there might be a new check that ensures that all unittests have either a @safe or a `@system attribute, because it helps to avoid regressions.

@wilzbach wilzbach added this to the 2.073.0-b0 milestone Dec 29, 2016
@wilzbach
Copy link
Member

I've added a rather extreme unittest which tests both stable and unstable versions of both predicate and index based remove, and after this fix all remove functions seem consistent.

Excellent work!

(I have marked this for 2.073.0-b0 milestone)

@WalterWaldron
Copy link
Contributor Author

Regarding your latest feedback:
I changed verify to assert on error instead of return a bool which should give 100% coverage.
I also Phobos idiom-ified all the unit test code and added the @safe attribute.

@wilzbach
Copy link
Member

Auto-merge toggled on

@wilzbach wilzbach merged commit 3c0b47a into dlang:master Dec 29, 2016
@WalterWaldron WalterWaldron deleted the fix16996 branch December 29, 2016 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants