-
Notifications
You must be signed in to change notification settings - Fork 205
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
Feature request: parameterize SortedList used in SortedDict through inheritance #204
Comments
See #195 |
I created an issue: In the meantime you still may adjust sortedcontainers I guess? This will be None if the python source code will not change, just like it currently is, but automatically gets the index as soon python changes it. |
If you want to add sth to the cpython issue, please let us know. If not, it seems the devs there convinced me that there is no urgent need to change "insort" to return the index, because doing bisect and then list.insert(...) one after the other would be the same speed... |
In #195, I mentioned "The other problem ..." but the first problem still remains (and is the bigger issue): """Getting the index of the item requires the positional index to be built which add() specifically avoids. I think this is a fine example for simply inheriting and implementing the needed functionality in your own code."""
This is a good point. SortedDict is not parameterized on the SortedList type. I don't think I'd want to make it an argument to
and your code would do:
|
Thank you. What do you think how much impact it will have to exchange the insort call with bisect_right and list.insert and returning the index in my custom sortedlist? Like 10% slower or more/less? Maybe you already made some tests regarding this and therefore decided against it. |
Hi, thanks for your work :)
would it be possible to add a new function to the SortedDict (and therefore also SortedList) which sets a key a new value and returns the index position in one go?
Eg.: index = sorteddict.setitem_returnindex(key,value)
Usecase:
I want to add a new key,value to the SortedDict and I want to know at which total index this key was sorted in. Since performance is important, I assume that such a combined method would be much faster than sorting it in and then again search the key to get the index.
I assume that when sorting the new key into the SortedDict, we already search for the correct index to insert it. So we should be able to simply return this index and then there is no need to search for it twice.
I already read the source code and tried to add it myself, but: 1) sortedcontainers is still frequently updated, I don't want to overwrite eg. the init of SortedDict to make it use a custom SortedList, because this might mess with future updates. 2) I did not fully understand the internal structure with lists and maxes yet :D And it seems bisect "insort" also does not return the index, which makes it more difficult =/ (I really don't understand why "insort" does not return the index, it would be so easy -.- )
The text was updated successfully, but these errors were encountered: