-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
Question on querying IntervalDict #45
Comments
Hello, I'm afraid the answer is no, there is no direct way to access the exact "keys" that were used to store a value. >>> d = P.IntervalDict()
>>> d[P.closed(0, 10)] = 'whatever'
>>> value = d.get(P.singleton(5))
>>> d.find(value)
[0,10] But it does not preserve the exact keys that were used to add a value into the dict, as illustrated next: >>> d = P.IntervalDict()
>>> d[P.closed(0, 10)] = 'whatever'
>>> d[P.closed(10, 20)] = 'whatever'
>>> value = d.get(P.singleton(5))
>>> d.query(value)
[0,20] ... and not I don't know if this "solution" based on Notice that the above solution is not very efficient, since it requires (1) to find intersections with >>> for key, value in d.items():
>>> if P.singleton(5) in key:
>>> break
>>> key
[0,20] |
I was actually not clear enough/oversimplifying when I said I wanted the interval used to store the value... 😄 What you describe is exactly what I would want, the interval that currently points to a value, even after new insertions caused it to join/split. In my use case dicts should be small enough that the performance penalty wouldn't be a problem, so the Thank you, I'll give it a go! |
My bad, it's not |
Ah, thanks. Just to add to the discussion, I'm not sure how frequent this use case is for users of the lib in general, but would it be possible in theory to add a new convenience method |
Thanks for the suggestion. However, it would be a simple wrapper around |
Sorry to come back to this after so long, but I've gone to implement your suggestion today and one drawback it has is the possibility that the same value is associated to multiple intervals in the dict. So when I call One (admittedly not too huge) more reason in favour of the convenience method... 😄 |
I'm really sorry but I did not understand your question ;-) could you clarify what you do, what's you got and what you expected? I'm willing to help you ;-) |
Sorry for not being clear enough... :) What I meant is, if there are 2 disjoint intervals, say [0,10] and [20, 30] that are associated to the value 'whatever', when I do Not sure that helped or added to the confusion... 😄 Basically the idea is that when I do |
Ok, I got it ;-) Thank you ;) Indeed, the |
First of all, thank you so much for the incredibly useful library!
I'd like to know if it is possible to obtain the interval which was used to store a value in an IntervalDict when querying.
For example, if I store something with
d[P.closed(0, 10)] = 'whatever'
and then query the dict ford.get(P.singleton(5))
, is it possible for me to know that the interval in the dict that contains the interval I used for querying isP.closed(0, 10)
?Thanks again
The text was updated successfully, but these errors were encountered: