use crate::alloc_trait::TreeAllocator;
use crate::policy::LeafPolicy;
use crate::policy::RefPolicy as RefLeafPolicy;
use crate::tree::range::reverse_ctx::{
RevIntraLeafCopyStrategy, RevIntraLeafRefStrategy, RevValuesOnlyStrategy,
};
use super::RangeIter;
impl<P, A> RangeIter<'_, '_, P, A>
where
P: LeafPolicy,
A: TreeAllocator<P>,
{
#[inline]
#[must_use = "returns the number of entries visited"]
pub fn rev_for_each_ref<F>(mut self, mut visitor: F) -> usize
where
P: RefLeafPolicy,
F: FnMut(&[u8], &P::Value) -> bool,
{
if self.back_exhausted() {
return 0;
}
if !self.back_initialized() {
self.initialize_back();
if self.back_exhausted() {
return 0;
}
}
let start_bound_ikey: Option<u64> = self.start_bound.extract_ikey();
let rev = unsafe { self.rev.as_mut().unwrap_unchecked() };
let mut strategy = RevIntraLeafRefStrategy::new(&mut visitor);
rev.run_batch_reverse(
&mut strategy,
&self.start_bound,
start_bound_ikey,
self.guard,
)
}
#[inline]
#[must_use = "returns the number of entries visited"]
pub fn rev_for_each_intra_leaf_batch<F>(mut self, mut visitor: F) -> usize
where
F: FnMut(&[u8], P::Output) -> bool,
{
if self.back_exhausted() {
return 0;
}
if !self.back_initialized() {
self.initialize_back();
if self.back_exhausted() {
return 0;
}
}
let start_bound_ikey: Option<u64> = self.start_bound.extract_ikey();
let rev = unsafe { self.rev.as_mut().unwrap_unchecked() };
let mut strategy = RevIntraLeafCopyStrategy::new(&mut visitor);
rev.run_batch_reverse(
&mut strategy,
&self.start_bound,
start_bound_ikey,
self.guard,
)
}
#[inline]
#[must_use = "returns the number of entries visited"]
pub fn rev_for_each_values_batch<F>(mut self, mut visitor: F) -> usize
where
F: FnMut(P::Output) -> bool,
{
if self.back_exhausted() {
return 0;
}
if !self.back_initialized() {
self.initialize_back();
if self.back_exhausted() {
return 0;
}
}
let start_bound_ikey: Option<u64> = self.start_bound.extract_ikey();
let rev = unsafe { self.rev.as_mut().unwrap_unchecked() };
let mut strategy = RevValuesOnlyStrategy::new(&mut visitor);
rev.run_batch_reverse(
&mut strategy,
&self.start_bound,
start_bound_ikey,
self.guard,
)
}
}