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

Function delete

src/tree/binary/rb2.rs:261–292  ·  view source on GitHub ↗
(h: Option<NonNull<Node<K, V>>>, key: &K)

Source from the content-addressed store, hash-verified

259}
260
261fn delete<K, V>(h: Option<NonNull<Node<K, V>>>, key: &K) -> Option<NonNull<Node<K, V>>>
262where
263 K: Ord,
264{
265 let mut h = NodeQuery::new(h);
266 if key < h.get_key().unwrap() {
267 if !h.left().is_red() && !h.left().left().is_red() {
268 h.node = move_red_left(h.node);
269 }
270 h.set_left(delete(h.left().node, key));
271 } else {
272 if h.left().is_red() {
273 h.node = rotate_right(h.node);
274 }
275 if key == h.get_key().unwrap() && h.right().is_none() {
276 Node::release(h.node.unwrap());
277 return None;
278 }
279 if !h.right().is_red() && !h.right().left().is_red() {
280 h.node = move_red_right(h.node);
281 }
282 if key == h.get_key().unwrap() {
283 let x = unsafe { bst::find_min(h.right().node) };
284 h.copy_entry(x.unwrap());
285 h.set_right(del_min(h.right().node));
286 } else {
287 h.set_right(delete(h.right().node, key));
288 }
289 }
290
291 balance(h.node)
292}
293
294/*
295 h x

Callers 1

deleteMethod · 0.70

Calls 14

move_red_leftFunction · 0.85
move_red_rightFunction · 0.85
find_minFunction · 0.85
del_minFunction · 0.85
balanceFunction · 0.85
get_keyMethod · 0.80
is_redMethod · 0.80
is_noneMethod · 0.80
copy_entryMethod · 0.80
rotate_rightFunction · 0.70
leftMethod · 0.45
set_leftMethod · 0.45

Tested by

no test coverage detected