-
Notifications
You must be signed in to change notification settings - Fork 27
Description
At the moment the only way to change the values in the map is to insert new ones. There is no way to update existing ones. I understand that this has to do with the coalescing behaviour; if you change something, you have to check afterwards if it can be merged with an adjacent range. But having no mutable operations also makes some tasks really cumbersome.
In my particular case, I want to make a specific change to all items within a range, filling in gaps and splitting existing ranges at either end if necessary. To do that currently, I have to clone the items from the specified range, store them somewhere else, change them, then insert them back in. That temporary storage also needs an allocation, which is something I'd rather avoid as this is performance sensitive code.
Range coalescing can be useful for speed, but in my case above with a mutation-heavy workload, that speed benefit may well be lost. It also has the drawback that values need to be Eq
, and comparing values may be costly. I therefore propose an alternative:
- No coalescing is done anymore. Two touching ranges can have the same value.
Eq
is no longer needed. - Mutable operations can now be added since there is no invariant to uphold.
- Add a
split
method to split a range in two at a given key. - Add a
merge
method that does the coalescing manually. This method would have anEq
bound on the value.
This would give the user control over the coalescing behaviour, and they can decide to use it or not, or use it less frequently. It would also help with my case; I could now call split
at the ends of the range, then call range_mut
(to be written) to mutate the ranges in place.
I'm willing to implement these changes if wanted.