-
Notifications
You must be signed in to change notification settings - Fork 254
Updating a SortedMultiDict #815
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
Comments
This operation is not supported in SortedMultiDict. I would say that it is unlikely to get supported because it is an unusual operation that would be difficult to test and document (although not too difficult to implement). Here are some possible workarounds for the functionality you are looking for. (1) If you are changing many of the keys simultaneously, say, a constant fraction of all the keys, then you can rebuild the SortedMultiDict from scratch with the updated keys. In the current implementation of SortedMultiDict, this requires O(n log n) operations. In the updated version in pull request #787 the time requirement is reduced to O(n) because the update has a SortedMultiDict constructor that runs in O(n) time if the keys are already sorted. This pull request is currently under review and awaiting merging. (2) This and the next suggestion assume the case that you are modifying only a few keys. The next possibility is for you to hack the needed functionality into data structure yourself. First, in case you are not already familiar, take a look at the description of 2-3 trees on Wikipedia to understand the structure. To change a key in-place, first change the key of the entry of the (3) Another approach is to build a two-level data structure. The outer level would be a SortedDict that would store, for each "new" key, a 2-tuple of semitokens of an underlying SortedMultiDict that is indexed by the original keys. These two semitokens index the starting and ending position of records that correspond to this new key. For example, in your MWE, the SortedMultiDict would not change. The outer SortedDict would be initially |
Thanks @StephenVavasis For the current problem, I update keys only a few at a time (during an iteration over the whole SMD). I am closing the issue then :) |
Hi there!
I know there are a lot of things ongoing before v1, so maybe there are no solutions yet to my problem, but I am trying to update the keys of a SortedMultiDict.
For the current application, it happens that the order of the elements won't change, so I am okay with a dirty solution for a while.
As for a MWE, assume we have
One costly approach would be to store,
delete!
the 3 first elements, andinsert!
them again (to preserve the original order). I couldn't make thedelete!
method work with SMD and the associated token. It seems the documentation is still in progress regarding this.Any way I could get through it? (if I drop dict structures, I can probably do something with mutable linked list, but most likely the insertion of sorted elements dynamically won't be efficient)
The text was updated successfully, but these errors were encountered: