MCPcopy Index your code
hub / github.com/douchuan/algorithm / put

Function put

src/tree/binary/rb2.rs:201–217  ·  view source on GitHub ↗

insert the element in the subtree rooted at h

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

Source from the content-addressed store, hash-verified

199
200/// insert the element in the subtree rooted at h
201fn put<K, V>(h: Option<NonNull<Node<K, V>>>, key: K, val: V) -> Option<NonNull<Node<K, V>>>
202where
203 K: Ord,
204{
205 let mut h = NodeQuery::new(h);
206
207 match h.get_key() {
208 None => return Some(Node::new_leaf(key, Some(val), None)),
209 Some(h_key) => match key.cmp(h_key) {
210 Ordering::Equal => h.set_entry((key, Some(val))), // update val
211 Ordering::Less => h.set_left(put(h.left().node, key, val)),
212 Ordering::Greater => h.set_right(put(h.right().node, key, val)),
213 },
214 }
215
216 balance(h.node)
217}
218
219/// delete the min element rooted at h
220fn del_min<K, V>(h: Option<NonNull<Node<K, V>>>) -> Option<NonNull<Node<K, V>>> {

Callers 1

insertMethod · 0.85

Calls 8

balanceFunction · 0.85
get_keyMethod · 0.80
set_entryMethod · 0.80
cmpMethod · 0.45
set_leftMethod · 0.45
leftMethod · 0.45
set_rightMethod · 0.45
rightMethod · 0.45

Tested by

no test coverage detected