Skip to main content

splay_with_local_top_down

Function splay_with_local_top_down 

Source
pub unsafe fn splay_with_local_top_down<Spec, Data>(
    node: BstNodePtr<<Spec as BstSpec>::Data, <Spec as BstSpec>::Parent>,
) -> BstNodePtr<<Spec as BstSpec>::Data, <Spec as BstSpec>::Parent>
where Spec: BstSpec<Data = Data, Parent = WithParent<Data>>,
Expand description

Moves node to the root by propagating only the nodes involved in each rotation and returns the previous root.

ยงSafety

node and every pointer reachable through its auxiliary-parent chain must refer to live nodes of the same tree. Propagating an ancestor after its descendant must be valid for Spec.

Examples found in repository?
crates/competitive/src/tree/top_tree.rs (lines 385-388)
378    unsafe fn splay_top(node: TopPtr<S, A>) {
379        let root = if A::ROOT_TO_NODE_TOP_DOWN {
380            unsafe {
381                splay_operations::with_parent::splay::<TopBstSpec<S, A>, TopTreeData<S, A>>(node)
382            }
383        } else {
384            unsafe {
385                splay_operations::with_parent::splay_with_local_top_down::<
386                    TopBstSpec<S, A>,
387                    TopTreeData<S, A>,
388                >(node)
389            }
390        };
391        if root != node {
392            unsafe {
393                (*node.as_ptr()).data.belong = (*root.as_ptr()).data.belong.take();
394            }
395        }
396    }
397
398    #[inline]
399    unsafe fn splay_rake(node: RakePtr<S, A>) {
400        unsafe {
401            splay_operations::with_parent::splay_with_local_top_down::<
402                RakeBstSpec<S, A>,
403                RakeData<S, A>,
404            >(node)
405        };
406    }
More examples
Hide additional examples
crates/competitive/src/tree/link_cut_tree.rs (lines 220-223)
213    unsafe fn splay(node: LinkCutPtr<S>) {
214        let root = if S::ROOT_TO_NODE_TOP_DOWN {
215            unsafe {
216                splay_operations::with_parent::splay::<LinkCutBstSpec<S>, LinkCutData<S>>(node)
217            }
218        } else {
219            unsafe {
220                splay_operations::with_parent::splay_with_local_top_down::<
221                    LinkCutBstSpec<S>,
222                    LinkCutData<S>,
223                >(node)
224            }
225        };
226        if root != node {
227            unsafe {
228                LinkCutBstSpec::<S>::with_two_inner_mut(root, node, S::transfer_path_parent);
229            }
230        }
231    }