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

[stdlib] Implementing O(1) methods on CountableClosedRange #2993

Merged
merged 2 commits into from
Jun 17, 2016

Conversation

austinzheng
Copy link
Contributor

@austinzheng austinzheng commented Jun 12, 2016

What's in this pull request?

Functional changes and additional unit test coverage for CountableRange and CountableClosedRange.

All tests pass on OS X.

@gribozavr


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

Changes:

  • Implemented O(1) index(_:offsetBy:) and distance(from:to:) methods on CountableClosedRange
  • Fixed some unit tests
  • Added many more unit tests for Countable*Range index APIs

@moiseev moiseev changed the title Implementing O(1) methods on CountableClosedRange [stdlib] Implementing O(1) methods on CountableClosedRange Jun 13, 2016
@moiseev
Copy link
Contributor

moiseev commented Jun 13, 2016

@swift-ci Please test

return 1 + limit.distance(to: right)
case (.pastEnd, .pastEnd):
// end <--> end
return limit.distance(to: limit)
Copy link
Contributor

Choose a reason for hiding this comment

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

Bound.Stride conforms to Integer, so this can be 0 I guess?

@moiseev
Copy link
Contributor

moiseev commented Jun 13, 2016

Thanks @austinzheng for doing this. Please let me know once you've updated the tests and I'll be happy to merge it in.

@moiseev moiseev self-assigned this Jun 13, 2016
@austinzheng
Copy link
Contributor Author

I also have another PR, whenever you or Dmitri have time: #2940

@austinzheng
Copy link
Contributor Author

I need to rewrite a bunch of these tests. I'll ping you when I have the updated code ready.

@austinzheng austinzheng force-pushed the az-rangework branch 3 times, most recently from 3c6aa17 to 49241da Compare June 14, 2016 04:52
@austinzheng
Copy link
Contributor Author

austinzheng commented Jun 14, 2016

@moiseev

I fixed the issues raised in your comments, addressed some additional bugs, and rewrote some of the test suites I added since they were not properly implemented before. The tests in question pass; I'm running the entire test suite on OS X right now and will comment again when it finishes. Otherwise, it's ready.

@austinzheng
Copy link
Contributor Author

All tests pass on my OS X machine.

@austinzheng austinzheng force-pushed the az-rangework branch 2 times, most recently from e0d164e to c8e5228 Compare June 14, 2016 05:57
}
previousValue = range[idx].value
}
// Iterate once more to get to the 'before start' position
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not look right. Past-end is a valid index, before-start is not. Valid indices can only be in the following range [startIndex, endIndex).

Copy link
Contributor Author

@austinzheng austinzheng Jun 14, 2016

Choose a reason for hiding this comment

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

Yes. In addition to the comment being misleading, this specific test is really confusingly written and I will redo it to make the intent clearer.

@austinzheng
Copy link
Contributor Author

I looked into that test more closely. The test was correct, but written in a very confusing way, so I changed it around and made the preconditions it tests explicit in a comment. The "before start index" comment was simply wrong and I've removed it.

I'm happy to make any other changes you'd like. Also let me know if you want me to squash the commit. @moiseev

@austinzheng austinzheng force-pushed the az-rangework branch 5 times, most recently from df1da50 to 5d955f1 Compare June 16, 2016 07:53
Changes:
- Implemented O(1) `index(_:offsetBy:)` and `distance(from:to:)` methods on `CountableClosedRange`
- Fixed some unit tests
- Added many more unit tests for Countable*Range index APIs
@moiseev
Copy link
Contributor

moiseev commented Jun 16, 2016

@swift-ci Please test

@austinzheng
Copy link
Contributor Author

Looks like everything's in working order.

@moiseev moiseev merged commit 6231cca into swiftlang:master Jun 17, 2016
@@ -47,26 +47,64 @@ public struct ClosedRangeIndex<Bound> : Comparable
}
}

internal func _predecessor(upperBound limit: Bound) -> ClosedRangeIndex {
internal func _predecessor(
lowerBound: Bound, upperBound limit: Bound
Copy link
Contributor

Choose a reason for hiding this comment

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

At this point, now that you are passing both bounds, I think it would make sense to just move this code into its only callsite.

@moiseev
Copy link
Contributor

moiseev commented Jun 17, 2016

Ooops. Sorry, @gribozavr, I merged it before seeing your comments.

@gribozavr
Copy link
Contributor

NP.


/// Return the index `leftIndex` steps away from `start`, or the collection's
/// `endIndex` if `leftIndex` is `nil`.
func leftIndex<C: RandomAccessCollection>(forCollection c: C) -> C.Index {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use just for: for the label (Collection is redundant).

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even of:.

@gribozavr
Copy link
Contributor

@austinzheng Great work! 👍

@austinzheng
Copy link
Contributor Author

Thanks! I'll open a new PR to address these comments soon.

On Jun 16, 2016, at 9:30 PM, Dmitri Gribenko notifications@github.com wrote:

@austinzheng https://github.com/austinzheng Great work! 👍


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub #2993 (comment), or mute the thread https://github.com/notifications/unsubscribe/ADhCjj2Oa2_JeiEXJMX6gooouuKqnb9nks5qMiLdgaJpZM4IzteZ.

austinzheng added a commit to austinzheng/swift that referenced this pull request Jun 17, 2016
Changes:
- Moved only-used-once helper methods into call sites
- Parameterized tests that might expect a crash
- Fixed some comments and formatting; renamed some test helper APIs
@austinzheng austinzheng deleted the az-rangework branch June 19, 2016 04:19
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.

3 participants