Support range iterators in BiBTreeMap
Closed this issue · 4 comments
solarretrace commented
The std BTreeMap supports iteration over a subset of the map using a range (BTreeMap::range
, BTreeMap::range_mut
). If I understand correctly, the BiBTreeMap could support the same operation (in both directions) but not the _mut
version.
I'm happy to submit a PR if these methods are desirable and I find some time to add them. I have implementations prepared with the following signatures:
pub fn left_range<'a, Q, A>(&'a self, range: A) -> LeftRange<'a, L, R>
where
Rc<L>: Borrow<Q>,
A: std::ops::RangeBounds<Q>,
Q: Ord + ?Sized;
pub fn right_range<'a, Q, A>(&'a self, range: A) -> RightRange<'a, L, R>
where
Rc<R>: Borrow<Q>,
A: std::ops::RangeBounds<Q>,
Q: Ord + ?Sized;
billyrieger commented
See #16 (comment). This would be nice to have but it leaks implementation details.
solarretrace commented
You're probably right about Rc in the signature here, but I think these methods would still be usable with a more restricted signature:
pub fn left_range<'a, A>(&'a self, range: A) -> LeftRange<'a, L, R>
where A: std::ops::RangeBounds<L>;
pub fn right_range<'a, A>(&'a self, range: A) -> RightRange<'a, L, R>
where A: std::ops::RangeBounds<R>;
billyrieger commented
Yes, that looks like it should work. If you're up for making a PR I'd be happy to review it!
billyrieger commented
Closed by #18.