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

Function left_rotate

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

Source from the content-addressed store, hash-verified

806// 节点左旋
807#[inline]
808unsafe fn left_rotate<K: Ord + Debug, V>(tree: &mut RBTree<K, V>, x: *mut RBNode<K, V>) {
809 /*
810 * x 处左旋
811 * (x could also be the left child of p)
812 *
813 * p p
814 * \ \
815 * x --> y
816 * / \ / \
817 * y x
818 * / \ / \
819 * c c
820 */
821
822 let p = (*x).parent;
823 let y = (*x).right;
824 let c = (*y).left;
825
826 (*y).left = x;
827 (*x).parent = y;
828 (*x).right = c;
829 if !c.is_null() {
830 (*c).parent = x;
831 }
832 if p.is_null() {
833 tree.root = y;
834 } else if (*p).left == x {
835 (*p).left = y;
836 } else {
837 (*p).right = y;
838 }
839 (*y).parent = p;
840}
841
842// 节点右旋
843#[inline]

Callers 2

insert_fixupFunction · 0.85
delete_fixupFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected