左旋操作变换为: X Y / \ / \ a Y => X c / \ / \ b c a b */
(
mut root: Option<NonNull<Node<K, V>>>,
x: NonNull<Node<K, V>>,
)
| 202 | |
| 203 | */ |
| 204 | fn 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 | 右旋操作变换为: |