Add TreeMap::remove_between that can take abstract start and end points

This commit introduces a new adaptor trait for SeekTarget that works around
frustrating issues with lifetimes. It wraps the arguments in a newtype wrapper
that lives on the stack to avoid the lifetime getting extended to the caller
of the method.

This allows us to introduce a PathSuccessor object that can be passed as the
end argument of remove_between to remove a whole subtree.
This commit is contained in:
Nathan Sobo 2023-05-11 23:20:20 -06:00 committed by Mikayla Maki
parent 89352a2bdc
commit ee3637216e
No known key found for this signature in database
3 changed files with 94 additions and 114 deletions

View file

@ -5,7 +5,7 @@ use arrayvec::ArrayVec;
pub use cursor::{Cursor, FilterCursor, Iter};
use std::marker::PhantomData;
use std::{cmp::Ordering, fmt, iter::FromIterator, sync::Arc};
pub use tree_map::{TreeMap, TreeSet};
pub use tree_map::{TreeMap, TreeSet, PathDescendants};
#[cfg(test)]
const TREE_BASE: usize = 2;
@ -47,7 +47,7 @@ impl<'a, T: Summary> Dimension<'a, T> for T {
}
pub trait SeekTarget<'a, S: Summary, D: Dimension<'a, S>>: fmt::Debug {
fn cmp(&self, cursor_location: &D, cx: &S::Context) -> Ordering;
fn cmp(&self, cursor_location: &D, cx: &S::Context) -> Ordering;
}
impl<'a, S: Summary, D: Dimension<'a, S> + Ord> SeekTarget<'a, S, D> for D {