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

Function del_max

src/tree/binary/rb2.rs:239–259  ·  view source on GitHub ↗

delete the max element rooted at h

(h: Option<NonNull<Node<K, V>>>)

Source from the content-addressed store, hash-verified

237
238/// delete the max element rooted at h
239fn del_max<K, V>(h: Option<NonNull<Node<K, V>>>) -> Option<NonNull<Node<K, V>>> {
240 let mut h = NodeQuery::new(h);
241
242 if h.left().is_red() {
243 h.node = rotate_right(h.node);
244 }
245
246 if h.right().is_none() {
247 if let Some(h) = h.node.take() {
248 Node::release(h);
249 }
250 None
251 } else {
252 if !h.right().is_red() && !h.right().left().is_red() {
253 h.node = move_red_right(h.node);
254 }
255 let new_right = del_max(h.right().node);
256 h.set_right(new_right);
257 balance(h.node)
258 }
259}
260
261fn delete<K, V>(h: Option<NonNull<Node<K, V>>>, key: &K) -> Option<NonNull<Node<K, V>>>
262where

Callers 1

delete_maxMethod · 0.85

Calls 8

move_red_rightFunction · 0.85
balanceFunction · 0.85
is_redMethod · 0.80
is_noneMethod · 0.80
rotate_rightFunction · 0.70
leftMethod · 0.45
rightMethod · 0.45
set_rightMethod · 0.45

Tested by

no test coverage detected