BTree{Map,Set} range removal

It would be great if BTreeMap/BTreeSet were to have a remove_range method, that, instead of merely removing a single element (as the stable remove does), could remove all those within a range (similar to how BTree{Map,Set}::range iterates over those elements). Right now one would have to use BTree{Map,Set}::retain with a check like |k, _| !range.contains(k)) to achieve functionally the same behavior -- but that iterates over the entire collection. Range based removal would no longer need to visit the entire collection, as said collection is sorted.

This request is somewhat similar to BTreeMap::drain with a range.


When I have tried to implement this function, I found there are much more details then I think. So I opened a (pre-)RFC to describe my ideas first. See Pre-RFC: `{BTreeMap, BTreeSet}::drain` with a range.

1 Like