MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / right_rotate

Function right_rotate

publication/code/chapter08/rbtree.rs:844–876  ·  view source on GitHub ↗
(tree: &mut RBTree<K, V>, x: *mut RBNode<K, V>)

Source from the content-addressed store, hash-verified

842// 节点右旋
843#[inline]
844unsafe fn right_rotate<K: Ord + Debug, V>(tree: &mut RBTree<K, V>, x: *mut RBNode<K, V>) {
845 /*
846 * x 处右旋
847 * (x could also be the left child of p)
848 *
849 * p p
850 * \ \
851 * x --> y
852 * / \ / \
853 * y x
854 * / \ / \
855 * c c
856 */
857
858 let p = (*x).parent;
859 let y = (*x).left;
860 let c = (*y).right;
861
862 (*y).right = x;
863 (*x).parent = y;
864 (*x).left = c;
865 if !c.is_null() {
866 (*c).parent = x;
867 }
868 if p.is_null() {
869 tree.root = y;
870 } else if (*p).left == x {
871 (*p).left = y;
872 } else {
873 (*p).right = y;
874 }
875 (*y).parent = p;
876}
877
878// 替换节点值并更新节点关系
879#[inline]

Callers 2

insert_fixupFunction · 0.85
delete_fixupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected