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

Add Interval class #114

Closed
wants to merge 11 commits into from
Closed

Add Interval class #114

wants to merge 11 commits into from

Conversation

seaneagan
Copy link
Contributor

This still needs docs and a bit of formatting cleanup, but the tests are extensive, so it should be ready for general feedback.

Main inspirations for this were:

http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Range.html
http://en.wikipedia.org/wiki/Interval_(mathematics)

I put it in quiver.compare since I also want to add stuff from #60 there. quiver.comparables could also work, but that might not make as much sense if Interval or other functionality works with arbitrary Comparators instead of requing Comparables. quiver.math is another option.

I deprecated quiver.iterables.extent(iterable) in favor of new Interval.span(iterable).

@jtmcdole
Copy link
Member

jtmcdole commented May 7, 2014

Just letting you know I'll pick this up for review.

// See the License for the specific language governing permissions and
// limitations under the License.

part of quiver.compare;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think rather than quiver.compare, we might just want these in quiver.core (with your other compare PR). Another place for Interval could be quiver.math

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Do you prefer quiver.core or quiver.math? I have a slight preference for quiver.math, considering we may want an IntervalTree or similar in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went with quiver.math, it really is a math concept, the Bound class would feel out of place in quiver.core, and it has potential to expand in the future to e.g. multi-dimensional Intervals and IntervalTrees.

@justinfagnani
Copy link
Contributor

I was chatting w/ Chris about this, so added a few comments :)

@seaneagan
Copy link
Contributor Author

@jtmcdole @justinfagnani comments addressed, PTAL

/// Whether `this` [contains] any values.
bool get isEmpty {
if (lower == null || upper == null || Comparable.compare(lower, upper) < 0) return false;
return !(lowerClosed && upperClosed);
Copy link
Member

Choose a reason for hiding this comment

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

I would write this as return !isClosed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@jtmcdole
Copy link
Member

jtmcdole commented May 9, 2014

Are you following this up with an interval tree ;)

Note: I have an interval tree that I can adapt from TreeSet (it is the same code as treeset with a max subtree value at each node and some extra features for searching intervals).

@seaneagan
Copy link
Contributor Author

IntervalTree is all yours :). Hmm, I guess that would be in quiver.collections? In which case, maybe Interval should be in quiver.core after all? Or maybe everything Interval-related should go in a separate quiver.intervals library? Or a separate intervals package? There's also interval arithmetic.

@jtmcdole
Copy link
Member

jtmcdole commented May 9, 2014

IntervalTree would go in collections, but when I think of "Hey, I want an interval", I don't think I should include collections.

@seaneagan
Copy link
Contributor Author

Leaving Interval/Bound in quiver.math for now. My main concern with moving to quiver.core is Bound feels out of place there. We could probably remove Bound if we really want Interval in quiver.core.

@justinfagnani
Copy link
Contributor

John and I talked about this the other day, and one of the main arguments against quiver.math was that there are existing math libraries, and math is a huge domain that could have its own quiver-like package. I don't think we want to grow a significant math library in quiver, and don't want Interval to sit alone there either. Consider that dart:core has DateTime and Duration instead of a full-featured dart:time library, and I think this fits in well.

@seaneagan
Copy link
Contributor Author

Agreed. Moved to quiver.core.

class Bound<T> {

/// The boundary value.
final T value;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to differentiate upper and lower unbounded bounds? If there was, then Bound could be comparable.

@seaneagan
Copy link
Contributor Author

Going to publish this as its own package.

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

Successfully merging this pull request may close these issues.

None yet

5 participants