use core::borrow::Borrow;
use core::ops::Bound;
use core::ptr;
use super::super::node::inline_keys::SearchKey;
use super::super::node::internal::Internal;
use super::super::node::latch::Latched;
use super::super::node::leaf::Leaf;
use super::super::node::page::PageType;
use super::super::node_stack::ValMut;
use super::super::search::Found;
use super::super::walk::{DyingWalk, RangeWalk};
use super::LatchedTree;
use crate::allocator::Allocator;
use crate::inline_key::InlineKeyStrategy;
impl<K, V, S: InlineKeyStrategy<K>> LatchedTree<K, V, S> {
pub(crate) fn find_mut<Q>(&mut self, key: &Q) -> Option<&mut V>
where
K: Borrow<Q>,
Q: Ord + ?Sized,
{
let root_page = self.root_page()?;
let key = SearchKey::new(key);
if root_page.shared_prefix().place_outside(&key).is_some() {
return None;
}
root_page.node().find(&key, ()).map(Found::value_mut)
}
pub(crate) fn walk_mut(&mut self) -> RangeWalk<ValMut<'_, K, V>, K, V, Latched<S>>
where
K: Ord,
{
match self.root_page() {
Some(root_page) => RangeWalk::new::<K>(root_page, Bound::Unbounded, Bound::Unbounded),
None => RangeWalk::EMPTY,
}
}
pub(crate) fn take_dying_walk<A: Allocator>(
&mut self,
alloc: A,
) -> DyingWalk<K, V, Latched<S>, A> {
let root_page = self.root_page();
*self.root.get_mut() = ptr::null_mut();
*self.rightmost_leaf.get_mut() = ptr::null_mut();
self.free.deallocate_all(
&alloc,
Leaf::<K, V, Latched<S>>::page_layout(),
Internal::<K, V, Latched<S>>::page_layout(),
);
DyingWalk::new(root_page, usize::MAX, alloc)
}
}