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 Predecessible and methods to Interval #262

Merged
merged 6 commits into from Feb 25, 2014
Merged

Add Predecessible and methods to Interval #262

merged 6 commits into from Feb 25, 2014

Conversation

johnynek
Copy link
Collaborator

This also improves the tests on Interval by actually generating Intersections (whoops), which uncovered a bug when doing Intersection.intersect with anything other than another Intersection.

@johnynek
Copy link
Collaborator Author

closes #257

implicit def numPrev[N: Numeric]: Predecessible[N] = new NumericPredecessible[N]
}

class NumericPredecessible[@specialized(Int,Long,Float,Double) T:Numeric] extends Predecessible[T] {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

remove the specialized. Option isn't, so what's the point?

def iteratePrev[T](first: T)(implicit p: Predecessible[T]): Iterable[T] =
p.iteratePrev(first)

implicit def intergalPrev[N: Integral]: Predecessible[N] = new IntegralPredecessible[N]
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

typo: intergal. We need spell checkers that understand camelCase and under_scores.

* it this way, it does not mean it is empty or universe, etc... (there
* are other cases).
*/
def toLeftClosedRightOpen(implicit s: Successible[T]): Option[(T, T)] =
Copy link
Contributor

Choose a reason for hiding this comment

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

How to you imagine this being used? This seems like a terribly specific method. I guess I don't want to have 4 methods for all of the kinds, and would rather thing of a more general way to let people transforms intervals into forms that they wnt

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, we actually have a lot of interval parsing code in summingbird that is a pain given how general Intervals can be. This was for the common cases of finite interval that can be expressed as >= low, < high, which has the benefit of being easy to split: given low < h1 < high, then you can break this into two adjacent intervals: (low, h1), (h1, high).

Especially when converting to existing code that uses ranges like this, this method can be useful.

Copy link
Contributor

Choose a reason for hiding this comment

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

The issues I've seen are around super-intervals (if that's the right word), e.g., batches being a superset of timestamps. Would it make sense to optimize around this?

For example, something like:

def toIntervalOf[U](implicit mapping: Injection[T, Interval[U]]): Interval[U]

Maybe it should be abstracted a different way though, to more simply handle cases like going from timestamp back to batch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is an interesting case. So far, we have this mapNonDecreasing on intervals, but your point is nice: often a value in one case is a interval in the other. Such as: Injection[BatchID, Interval[Timestamp]].

If [B1, B2), that means that you have [least(time(B1)), least(time(B2)))

Similarly:

[B1, B2] => [least(time(B1)), greatest(time(B2))]
(B1, B2) => [greatest(time(B1)), least(time(B2)))
etc…

I think this is a useful pattern. Consider The truncation of Injection[Int, Interval[Double]] 1 => [1.0, 2.0) for instance. Though, really we might want to loosen it to Injection[Interval[Int], Interval[Double]], this is what it sounds like you were saying with supersets: If and interval is a super-interval of another, it means there is an Injection[Interval[T], Interval[U]] right?

I'd rather follow this up with more code moved from summingbird into this interval, successible, set of stuff. Can we do this in a next PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps the proper abstraction is to have a "smallest containing interval" and "largest contained interval", if we want to also cleanly handle cases where interval edges don't necessarily line up, such as when going from Timestamp to BatchID.

Anyway, separate PRs is better.

@jcoveney
Copy link
Contributor

I am digging this, Oscar.

@ianoc
Copy link
Collaborator

ianoc commented Feb 19, 2014

LGTM, if no objections pop up I'll merge in the morning

@johnynek
Copy link
Collaborator Author

@ianoc @jcoveney @jnievelt anyone want to merge this one?

@jcoveney
Copy link
Contributor

@johnynek giving it a final look and will merge shortly

jcoveney added a commit that referenced this pull request Feb 25, 2014
Add Predecessible and methods to Interval
@jcoveney jcoveney merged commit 0c8eabe into develop Feb 25, 2014
@jcoveney jcoveney deleted the predecessible branch February 25, 2014 18:55
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.

None yet

4 participants