use crate::{
tree::{
mut_gen::{
Borrowed,
WalkMut,
WalkMutPath,
},
InsertPosition,
Node,
TreeProperties,
WalkedDirection,
},
walk_mut::NodeOrTree,
};
use super::{
IterMutBorrowedInOrder,
IterMutBorrowedLeaf,
IterMutBorrowedLeafFull,
IterMutBorrowedPostOrder,
IterMutBorrowedPreOrder,
};
pub struct WalkMutBorrowed<'r, TP: TreeProperties + 'r, D = (), A = ()> {
pub(in crate::tree) inner: WalkMut<'r, TP, Borrowed, D, A>,
}
impl<'r, TP, D, A> WalkMutBorrowed<'r, TP, D, A>
where
TP: TreeProperties,
{
pub fn up(&mut self) -> Option<D> {
self.inner.up()
}
pub fn up_with(&mut self) -> Option<(D, A)> {
self.inner.up_with()
}
pub fn current(&self) -> NodeOrTree<Option<&Node<TP>>, &Node<TP>> {
self.inner.current()
}
pub fn current_mut(&mut self) -> NodeOrTree<Option<&mut Node<TP>>, &mut Node<TP>> {
self.inner.current_mut()
}
pub fn into_current_mut(self) -> NodeOrTree<Option<&'r mut Node<TP>>, &'r mut Node<TP>> {
self.inner.into_current_mut()
}
}
impl<'r, TP, D, A> WalkMutBorrowed<'r, TP, D, A>
where
TP: TreeProperties + 'r,
D: From<WalkedDirection>,
{
pub fn down_root_with(&mut self, add: A) -> bool {
self.inner.down_root_with(add)
}
pub fn down_left_with(&mut self, add: A) -> bool {
self.inner.down_left_with(add)
}
pub fn down_right_with(&mut self, add: A) -> bool {
self.inner.down_right_with(add)
}
pub fn down_with(&mut self, side: bool, add: A) -> bool {
self.inner.down_with(side, add)
}
}
impl<'r, TP, D> WalkMutBorrowed<'r, TP, D, ()>
where
TP: TreeProperties + 'r,
D: From<WalkedDirection>,
{
pub fn down_root(&mut self) -> bool {
self.inner.down_root()
}
pub fn down_left(&mut self) -> bool {
self.inner.down_left()
}
pub fn down_right(&mut self) -> bool {
self.inner.down_right()
}
pub fn down(&mut self, side: bool) -> bool {
self.inner.down(side)
}
}
impl<'r, TP, D> WalkMutBorrowed<'r, TP, D>
where
TP: TreeProperties + 'r,
D: From<WalkedDirection>,
{
pub fn path(&mut self, key: TP::Key) -> WalkMutBorrowedPath<'r, '_, TP, D> {
WalkMutBorrowedPath {
inner: self.inner.path(key),
}
}
pub fn goto_insert(&mut self, key: &TP::Key) -> Option<InsertPosition> {
self.inner.goto_insert(key)
}
}
impl<'r, TP> WalkMutBorrowed<'r, TP, WalkedDirection, ()>
where
TP: TreeProperties + 'r,
{
pub fn into_iter_pre_order(self) -> IterMutBorrowedPreOrder<'r, TP> {
self.inner.into_iter_pre_order().into()
}
pub fn next_pre_order(&mut self) -> Option<&mut Node<TP>> {
self.inner.next_pre_order()
}
pub fn into_iter_in_order(self) -> IterMutBorrowedInOrder<'r, TP> {
self.inner.into_iter_in_order().into()
}
pub fn next_in_order(&mut self) -> Option<&mut Node<TP>> {
self.inner.next_in_order()
}
pub fn into_iter_post_order(self) -> IterMutBorrowedPostOrder<'r, TP> {
self.inner.into_iter_post_order().into()
}
pub fn next_post_order(&mut self) -> Option<&mut Node<TP>> {
self.inner.next_post_order()
}
pub fn into_iter_leafs(self) -> IterMutBorrowedLeaf<'r, TP> {
self.inner.into_iter_leafs().into()
}
pub fn into_iter_full_leafs(self) -> IterMutBorrowedLeafFull<'r, TP> {
self.inner.into_iter_full_leafs().into()
}
pub fn next_leaf(&mut self) -> Option<&mut Node<TP>> {
self.inner.next_leaf()
}
}
pub struct WalkMutBorrowedPath<'r, 'w, TP, D = ()>
where
TP: TreeProperties + 'r,
{
inner: WalkMutPath<'r, 'w, TP, Borrowed, D>,
}
impl<'r, 'w, TP, D> WalkMutBorrowedPath<'r, 'w, TP, D>
where
TP: TreeProperties + 'r,
D: From<WalkedDirection>,
{
#[allow(clippy::should_implement_trait)] pub fn next(&mut self) -> Option<&mut Node<TP>> {
self.inner.next()
}
}