MCPcopy Create free account
hub / github.com/douchuan/algorithm / rotate_left

Function rotate_left

src/tree/binary/rb.rs:204–221  ·  view source on GitHub ↗

左旋操作变换为: X Y / \ / \ a Y => X c / \ / \ b c a b */

(
    mut root: Option<NonNull<Node<K, V>>>,
    x: NonNull<Node<K, V>>,
)

Source from the content-addressed store, hash-verified

202
203 */
204fn rotate_left<K, V>(
205 mut root: Option<NonNull<Node<K, V>>>,
206 x: NonNull<Node<K, V>>,
207) -> Option<NonNull<Node<K, V>>> {
208 let mut x = NodeQuery::new(Some(x));
209 let p = x.parent();
210 let mut y = x.right();
211 let a = x.left();
212 let b = y.left();
213 let c = y.right();
214 x.replace(y.node);
215 x.set_children(a.node, b.node);
216 y.set_children(x.node, c.node);
217 if p.is_none() {
218 root = y.node;
219 }
220 root
221}
222
223/*
224右旋操作变换为:

Callers 3

insert_fixFunction · 0.70
t_rotate_leftFunction · 0.70
t_rotate_rightFunction · 0.70

Calls 6

parentMethod · 0.80
replaceMethod · 0.80
set_childrenMethod · 0.80
is_noneMethod · 0.80
rightMethod · 0.45
leftMethod · 0.45

Tested by 2

t_rotate_leftFunction · 0.56
t_rotate_rightFunction · 0.56