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

[WIP] Implement SegmentTree #72

Closed
wants to merge 9 commits into from
Closed

[WIP] Implement SegmentTree #72

wants to merge 9 commits into from

Conversation

jsbean
Copy link
Member

@jsbean jsbean commented Dec 5, 2017

Ordered collections of intervals are ever present in models of music, as well as graphics.

SegmentTree structures provide a quicker access to interval-spanning elements than linear structures.

Furthermore, this will create a unified interface for similar interval-spanning structures.

@jsbean jsbean changed the title Implement IntervalTree [WIP] Implement SegmentTree Dec 6, 2017
}
}

subscript(interval: Interval<Metric>) -> SegmentTree {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the intended usage for subscript? seems like there are so many ways to implement it. it could even return [SegmentTree]. I think I would expect it to be either (1) an (ordered) list of the leaves whose given intervals fit inside interval (which could have a pretty nice recursive design), or (2) the largest SegmentTree that fits inside interval, with a precondition/error throw if none exists (which could also have a nice recursion).

fatalError()
}

func interval(containing offset: Metric, including bound: Interval<Metric>.Bound) -> Interval<Metric>? {
Copy link
Contributor

Choose a reason for hiding this comment

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

a little confused on the design here. is the idea to support interval queries for both open and closed sets? (like [a, b], [a, b), etc.)

Copy link
Contributor

Choose a reason for hiding this comment

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

mainly asking because the choices you've given are limiting and also I'm not sure i like the idea of this behavior changing within the same function

}
}

enum SegmentTree <Metric: SignedNumeric & Comparable> {
Copy link
Contributor

@mossheim mossheim Dec 7, 2017

Choose a reason for hiding this comment

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

where does SegmentTree fit into this design? i think this is a pretty interesting representation. wondering if duplicating the LHS and RHS bounds is necessary at every level; is that a simplicity/performance thing? because you could also define interval recursively as (left subtree's left bound, right subtree's right bound) in the branch case

@jsbean
Copy link
Member Author

jsbean commented Nov 17, 2018

See #166.

@jsbean jsbean closed this Nov 17, 2018
@jsbean jsbean deleted the interval-tree branch November 17, 2018 03:17
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.

2 participants