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

Function insert

src/tree/binary/rb.rs:141–153  ·  view source on GitHub ↗
(root: Option<NonNull<Node<K, V>>>, key: K, val: V)

Source from the content-addressed store, hash-verified

139}
140
141fn insert<K, V>(root: Option<NonNull<Node<K, V>>>, key: K, val: V) -> Option<NonNull<Node<K, V>>>
142where
143 K: Ord,
144{
145 // 插入过程与bst是一样的
146 if let Ok(x) = unsafe { bst::insert(root, key, val) } {
147 let root = if root.is_none() { Some(x) } else { root };
148 // 修正,使树恢复平衡
149 insert_fix(root, Some(x))
150 } else {
151 None
152 }
153}
154
155fn insert_fix<K, V>(
156 root: Option<NonNull<Node<K, V>>>,

Callers 4

insertMethod · 0.70
t_insertFunction · 0.70
t_rotate_leftFunction · 0.70
t_rotate_rightFunction · 0.70

Calls 2

insert_fixFunction · 0.85
is_noneMethod · 0.80

Tested by 3

t_insertFunction · 0.56
t_rotate_leftFunction · 0.56
t_rotate_rightFunction · 0.56