Open Wu-Chenyang opened 6 days ago
If you are interested in these changes, I can help with submitting a pull request.
I would recommend against changing the API for getindex
. Although I see the logic of the request, this API has been in place for 10 years, and changing it now could break many existing codes.
As for loosening the restriction in the API of searchsortedfirst
and its relatives: I can see that it is sensible for your use-case. I also see the pitfall that some future user could be misled into thinking that the sorted containers allow for two incompatible orderings simultaneously. So I don't have a strong opinion either way.
I see. Indeed, the changes in getindex
and searchsortedfirst
are not necessary even in my use case. I think your prudent decision is correct. What about the addition of nextind
, prevind
, and checkbounds
?
Yes, it would make sense to implement nextind
and prevind
and checkbounds
. Furthermore, it would probably make sense to deprecate advance
and regress
in favor of nextind
and prevind
from Base
, since a near-term goal for the package is to make the API more consistent with Base
. We wouldn't want to do this overnight since it would break existing codes, but it could be phased in over a few release cycles.
In my application, I find it's useful to define the following APIs for SortedContainer.
The first three functions
checkbounds
,nextind
,prevind
are straightforward and align well with existing APIs. Thegetindex
functions forIntSemiToken
have been implemented forSortedDict
andSortedMultiDict
, which return only the values. I modified them to return key-value pairs, because it is natural to do so in my application. Besides, given the existence of anothergetindex
function that retrieves thevalue
using thekey
, I think retrievingkey-value
pairs usingIntSemiToken
seems a natural choice. Of course, it might not be a good choice in general. How do you think about these changes?Here is a piece of my application code for motivating the changes. It uses the general APIs for sorted containers to simultaneously handle sorted AbstractVector and SortedDict.
I also tried to use the
SortedSet
as the container in this code block but encountered a problem thatsearchsortedlast
forSortedSet
tries to convert thet::Real
toObservation
before comparing it to other observations in the container. I think this compulsory conversion might not be necessary. In some cases, it is natural to directly compare objects of different types. The above code is an example.