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

Function rotate_right

src/tree/binary/rb.rs:233–250  ·  view source on GitHub ↗

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

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

Source from the content-addressed store, hash-verified

231
232 */
233fn rotate_right<K, V>(
234 mut root: Option<NonNull<Node<K, V>>>,
235 y: NonNull<Node<K, V>>,
236) -> Option<NonNull<Node<K, V>>> {
237 let mut y = NodeQuery::new(Some(y));
238 let p = y.parent();
239 let mut x = y.left();
240 let a = x.left();
241 let b = x.right();
242 let c = y.right();
243 y.replace(x.node);
244 y.set_children(b.node, c.node);
245 x.set_children(a.node, y.node);
246 if p.is_none() {
247 root = x.node;
248 }
249 root
250}
251
252#[test]
253fn t_insert() {

Callers 2

insert_fixFunction · 0.70
t_rotate_rightFunction · 0.70

Calls 6

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

Tested by 1

t_rotate_rightFunction · 0.56