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
SortedList/SortedKeyList update/add insertion order inconsistency #158
Comments
Also, just to be clear, no-one should be dependent on any order that has been unspecified (because the object was never told to sort beyond the key given), but the behavior is inconsistent depending on internal logic, so it seems like a change isn't out of the question. |
I recall seeing this behavior and I wasn’t sure if it mattered. To be clear, there’s no invariant that’s violated internally. The add() logic uses bisect_left just like the update() logic but the update() logic preserves the order of the elements it was given originally. If you want it to be consistent then a simple method override that always calls add() seems like a workaround. |
This issue matters somewhat in my application when trying to track down other things outside of the
I agree that a workaround like you suggest would technically work, but the performance would not be a good as a single My tests through benchmarking have shown that performance is comparable when making the change I suggest since the existing array is just being modified in a different place (beginning vs end). |
Internally of the
update()
methods ofSortedList
andSortedKeyList
, there is a fork in the logic of whether or not toadd()
each element of the iterator passed toupdate()
or to extend the iterator passed to update with the elements currently stored in theSortedList
/SortedKeyList
object by a condition on a ratio of the count of element in the external iterator and the elements contained in the SL/SKL object.Depending on whether or not external elements are added by
add()
or the SL/SKL object is reloaded from the result ofextend()
ing the external iterable, the order that the incoming elements end up in the resulting object can be different. This is only the case when the key to sort by is equivalent between objects being compared.Example:
For the SL/SKL and iterator size ratios applicable for the
update()
method to use the extension logic fork, the order of elements in how they show up in the final list is inconsistent.I have a suggestion for a fix for this by essentially prepending the existing elements to the incoming iterator rather than appending (by extending) them. I plan to submit a pull request soon...
The text was updated successfully, but these errors were encountered: