use crate::{
tree::{
mut_gen::{
Owned,
WalkMut,
WalkMutPath,
},
InsertPosition,
Node,
TreeProperties,
WalkedDirection,
},
walk_mut::NodeOrTree,
};
use super::{
IterMutOwnedInOrder,
IterMutOwnedLeaf,
IterMutOwnedLeafFull,
IterMutOwnedPostOrder,
IterMutOwnedPreOrder,
};
pub struct WalkMutOwned<'r, TP: TreeProperties + 'r, D = (), A = ()> {
pub(in crate::tree) inner: WalkMut<'r, TP, Owned, D, A>,
}
impl<'r, TP, D, A> WalkMutOwned<'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> WalkMutOwned<'r, TP, WalkedDirection, ()>
where
TP: TreeProperties + 'r,
{
pub fn delete_current(&mut self) -> Option<WalkedDirection> {
self.inner.delete_current()
}
}
impl<'r, TP, A> WalkMutOwned<'r, TP, WalkedDirection, A>
where
TP: TreeProperties + 'r,
{
pub fn delete_current_with(&mut self) -> Option<(WalkedDirection, A)> {
self.inner.delete_current_with()
}
pub fn compact_if_empty<F>(&mut self, is_empty: F)
where
F: Fn(&TP::Value) -> bool,
{
self.inner.compact_if_empty(is_empty)
}
}
impl<'r, TP, D, A> WalkMutOwned<'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> WalkMutOwned<'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> WalkMutOwned<'r, TP, D>
where
TP: TreeProperties + 'r,
D: From<WalkedDirection>,
{
pub fn path(&mut self, key: TP::Key) -> WalkMutOwnedPath<'r, '_, TP, D> {
WalkMutOwnedPath {
inner: self.inner.path(key),
}
}
pub fn goto_insert(&mut self, key: &TP::Key) -> Option<InsertPosition> {
self.inner.goto_insert(key)
}
}
impl<'r, TP, D> WalkMutOwned<'r, TP, D>
where
TP: TreeProperties + 'r,
D: From<WalkedDirection>,
{
pub fn insert(&mut self, key: TP::Key) -> &mut Node<TP> {
self.inner.insert(key)
}
}
impl<'r, TP> WalkMutOwned<'r, TP, WalkedDirection, ()>
where
TP: TreeProperties + 'r,
{
pub fn into_iter_pre_order(self) -> IterMutOwnedPreOrder<'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) -> IterMutOwnedInOrder<'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) -> IterMutOwnedPostOrder<'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) -> IterMutOwnedLeaf<'r, TP> {
self.inner.into_iter_leafs().into()
}
pub fn into_iter_full_leafs(self) -> IterMutOwnedLeafFull<'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 WalkMutOwnedPath<'r, 'w, TP, D = ()>
where
TP: TreeProperties + 'r,
{
inner: WalkMutPath<'r, 'w, TP, Owned, D>,
}
impl<'r, 'w, TP, D> WalkMutOwnedPath<'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()
}
}