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

Support open/closed intervals in StaticIntervalTree #227

Open
laurisvan opened this issue Sep 3, 2024 · 4 comments
Open

Support open/closed intervals in StaticIntervalTree #227

laurisvan opened this issue Sep 3, 2024 · 4 comments

Comments

@laurisvan
Copy link

First of all, thanks for a great library, we appreciate the work you have put into this.

We are using StaticIntervalTree to model time intervals [start,end) and use intervalsContainingPoint and also a bit of intervalsOverlappingInterval. As far as we understand, StaticIntervalTree models all intervals as closed. In our cases, the intervals are always open form the end, so we need to perform extra checks after the function calls.

While the extra checks are not a big problem performance-wise or functionality-wise, I thought this might be useful addition to the library? For our case the intervals are always interpreted the same way, e.g. we do not mix open and close intervals. Thus, it would be sufficient to add the interval interpretation as optional part of function call, like

tree.intervalsContainingPoint(0, { openBegin: false, openEnd: true}) 
tree.intervalsOverlappingInterval([0, 1], { openBegin: false, openEnd: true}) 

Do you see this as something that could belong to the domain of this library? If so, would you accept a contribution?

@Yomguithereal
Copy link
Owner

Out of curiosity, are your interval considering items with trivial successors/predecessors (like integers) or more like floats/dates?

@laurisvan
Copy link
Author

Out of curiosity, are your interval considering items with trivial successors/predecessors (like integers) or more like floats/dates?

Dates definitely, but for the sake of Mnemonist, we convert them to integers (unix timestamps). The times we deal with, are exact.

@Yomguithereal
Copy link
Owner

Then, if what you need is just conditions about which comparison operators to use in the function bodies, and it does not have a negligible performance impact, I would gladly review a PR on subject @laurisvan. This said, what I don't remember well and could be a little bit weird API wise is that the constructor is not able to consider other intervals than [close, close], but the getting functions can? I am wondering.

@laurisvan
Copy link
Author

Sorry for the late reply - we had a pretty hectic release crunch happening. I will try to familiarise with the constructor case and StaticIntervalTree internals. If it is indeed so, I agree that it is better do one thing right than several things half-right.

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

No branches or pull requests

2 participants